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.

74 lines
2.0KB

  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. #ifdef CONFIG_MUXERS
  23. static int mpjpeg_write_header(AVFormatContext *s)
  24. {
  25. uint8_t buf1[256];
  26. snprintf(buf1, sizeof(buf1), "--%s\n", BOUNDARY_TAG);
  27. put_buffer(&s->pb, buf1, strlen(buf1));
  28. put_flush_packet(&s->pb);
  29. return 0;
  30. }
  31. static int mpjpeg_write_packet(AVFormatContext *s, AVPacket *pkt)
  32. {
  33. uint8_t buf1[256];
  34. snprintf(buf1, sizeof(buf1), "Content-type: image/jpeg\n\n");
  35. put_buffer(&s->pb, buf1, strlen(buf1));
  36. put_buffer(&s->pb, pkt->data, pkt->size);
  37. snprintf(buf1, sizeof(buf1), "\n--%s\n", BOUNDARY_TAG);
  38. put_buffer(&s->pb, buf1, strlen(buf1));
  39. put_flush_packet(&s->pb);
  40. return 0;
  41. }
  42. static int mpjpeg_write_trailer(AVFormatContext *s)
  43. {
  44. return 0;
  45. }
  46. static AVOutputFormat mpjpeg_format = {
  47. "mpjpeg",
  48. "Mime multipart JPEG format",
  49. "multipart/x-mixed-replace;boundary=" BOUNDARY_TAG,
  50. "mjpg",
  51. 0,
  52. CODEC_ID_NONE,
  53. CODEC_ID_MJPEG,
  54. mpjpeg_write_header,
  55. mpjpeg_write_packet,
  56. mpjpeg_write_trailer,
  57. };
  58. int jpeg_init(void)
  59. {
  60. av_register_output_format(&mpjpeg_format);
  61. return 0;
  62. }
  63. #endif //CONFIG_MUXERS