You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.8KB

  1. /*
  2. * Multipart JPEG format
  3. * Copyright (c) 2000, 2001, 2002, 2003 Fabrice Bellard.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include "avformat.h"
  20. /* Multipart JPEG */
  21. #define BOUNDARY_TAG "ffserver"
  22. static int mpjpeg_write_header(AVFormatContext *s)
  23. {
  24. uint8_t buf1[256];
  25. snprintf(buf1, sizeof(buf1), "--%s\n", BOUNDARY_TAG);
  26. put_buffer(&s->pb, buf1, strlen(buf1));
  27. put_flush_packet(&s->pb);
  28. return 0;
  29. }
  30. static int mpjpeg_write_packet(AVFormatContext *s, AVPacket *pkt)
  31. {
  32. uint8_t buf1[256];
  33. snprintf(buf1, sizeof(buf1), "Content-type: image/jpeg\n\n");
  34. put_buffer(&s->pb, buf1, strlen(buf1));
  35. put_buffer(&s->pb, pkt->data, pkt->size);
  36. snprintf(buf1, sizeof(buf1), "\n--%s\n", BOUNDARY_TAG);
  37. put_buffer(&s->pb, buf1, strlen(buf1));
  38. put_flush_packet(&s->pb);
  39. return 0;
  40. }
  41. static int mpjpeg_write_trailer(AVFormatContext *s)
  42. {
  43. return 0;
  44. }
  45. AVOutputFormat mpjpeg_muxer = {
  46. "mpjpeg",
  47. "Mime multipart JPEG format",
  48. "multipart/x-mixed-replace;boundary=" BOUNDARY_TAG,
  49. "mjpg",
  50. 0,
  51. CODEC_ID_NONE,
  52. CODEC_ID_MJPEG,
  53. mpjpeg_write_header,
  54. mpjpeg_write_packet,
  55. mpjpeg_write_trailer,
  56. };