yuv4mpeg.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. /*
  2. * YUV4MPEG format
  3. * Copyright (c) 2001, 2002, 2003 Fabrice Bellard
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "avformat.h"
  22. #include "internal.h"
  23. #include "libavutil/pixdesc.h"
  24. #define Y4M_MAGIC "YUV4MPEG2"
  25. #define Y4M_FRAME_MAGIC "FRAME"
  26. #define Y4M_LINE_MAX 256
  27. struct frame_attributes {
  28. int interlaced_frame;
  29. int top_field_first;
  30. };
  31. #if CONFIG_YUV4MPEGPIPE_MUXER
  32. static int yuv4_generate_header(AVFormatContext *s, char* buf)
  33. {
  34. AVStream *st;
  35. int width, height;
  36. int raten, rated, aspectn, aspectd, n;
  37. char inter;
  38. const char *colorspace = "";
  39. st = s->streams[0];
  40. width = st->codec->width;
  41. height = st->codec->height;
  42. av_reduce(&raten, &rated, st->codec->time_base.den,
  43. st->codec->time_base.num, (1UL << 31) - 1);
  44. aspectn = st->sample_aspect_ratio.num;
  45. aspectd = st->sample_aspect_ratio.den;
  46. if (aspectn == 0 && aspectd == 1)
  47. aspectd = 0; // 0:0 means unknown
  48. inter = 'p'; /* progressive is the default */
  49. if (st->codec->coded_frame && st->codec->coded_frame->interlaced_frame)
  50. inter = st->codec->coded_frame->top_field_first ? 't' : 'b';
  51. switch (st->codec->pix_fmt) {
  52. case PIX_FMT_GRAY8:
  53. colorspace = " Cmono";
  54. break;
  55. case PIX_FMT_GRAY16:
  56. colorspace = " Cmono16";
  57. break;
  58. case PIX_FMT_YUV411P:
  59. colorspace = " C411 XYSCSS=411";
  60. break;
  61. case PIX_FMT_YUV420P:
  62. switch (st->codec->chroma_sample_location) {
  63. case AVCHROMA_LOC_TOPLEFT: colorspace = " C420paldv XYSCSS=420PALDV"; break;
  64. case AVCHROMA_LOC_LEFT: colorspace = " C420mpeg2 XYSCSS=420MPEG2"; break;
  65. default: colorspace = " C420jpeg XYSCSS=420JPEG"; break;
  66. }
  67. break;
  68. case PIX_FMT_YUV422P:
  69. colorspace = " C422 XYSCSS=422";
  70. break;
  71. case PIX_FMT_YUV444P:
  72. colorspace = " C444 XYSCSS=444";
  73. break;
  74. case PIX_FMT_YUV420P9:
  75. colorspace = " C420p9 XYSCSS=420P9";
  76. break;
  77. case PIX_FMT_YUV422P9:
  78. colorspace = " C422p9 XYSCSS=422P9";
  79. break;
  80. case PIX_FMT_YUV444P9:
  81. colorspace = " C444p9 XYSCSS=444P9";
  82. break;
  83. case PIX_FMT_YUV420P10:
  84. colorspace = " C420p10 XYSCSS=420P10";
  85. break;
  86. case PIX_FMT_YUV422P10:
  87. colorspace = " C422p10 XYSCSS=422P10";
  88. break;
  89. case PIX_FMT_YUV444P10:
  90. colorspace = " C444p10 XYSCSS=444P10";
  91. break;
  92. case PIX_FMT_YUV420P16:
  93. colorspace = " C420p16 XYSCSS=420P16";
  94. break;
  95. case PIX_FMT_YUV422P16:
  96. colorspace = " C422p16 XYSCSS=422P16";
  97. break;
  98. case PIX_FMT_YUV444P16:
  99. colorspace = " C444p16 XYSCSS=444P16";
  100. break;
  101. }
  102. /* construct stream header, if this is the first frame */
  103. n = snprintf(buf, Y4M_LINE_MAX, "%s W%d H%d F%d:%d I%c A%d:%d%s\n",
  104. Y4M_MAGIC, width, height, raten, rated, inter,
  105. aspectn, aspectd, colorspace);
  106. return n;
  107. }
  108. static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt)
  109. {
  110. AVStream *st = s->streams[pkt->stream_index];
  111. AVIOContext *pb = s->pb;
  112. AVPicture *picture, picture_tmp;
  113. int* first_pkt = s->priv_data;
  114. int width, height, h_chroma_shift, v_chroma_shift;
  115. int i;
  116. char buf2[Y4M_LINE_MAX + 1];
  117. char buf1[20];
  118. uint8_t *ptr, *ptr1, *ptr2;
  119. memcpy(&picture_tmp, pkt->data, sizeof(AVPicture));
  120. picture = &picture_tmp;
  121. /* for the first packet we have to output the header as well */
  122. if (*first_pkt) {
  123. *first_pkt = 0;
  124. if (yuv4_generate_header(s, buf2) < 0) {
  125. av_log(s, AV_LOG_ERROR,
  126. "Error. YUV4MPEG stream header write failed.\n");
  127. return AVERROR(EIO);
  128. } else {
  129. avio_write(pb, buf2, strlen(buf2));
  130. }
  131. }
  132. /* construct frame header */
  133. snprintf(buf1, sizeof(buf1), "%s\n", Y4M_FRAME_MAGIC);
  134. avio_write(pb, buf1, strlen(buf1));
  135. width = st->codec->width;
  136. height = st->codec->height;
  137. ptr = picture->data[0];
  138. switch (st->codec->pix_fmt) {
  139. case PIX_FMT_GRAY8:
  140. case PIX_FMT_YUV411P:
  141. case PIX_FMT_YUV420P:
  142. case PIX_FMT_YUV422P:
  143. case PIX_FMT_YUV444P:
  144. break;
  145. case PIX_FMT_GRAY16:
  146. case PIX_FMT_YUV420P9:
  147. case PIX_FMT_YUV422P9:
  148. case PIX_FMT_YUV444P9:
  149. case PIX_FMT_YUV420P10:
  150. case PIX_FMT_YUV422P10:
  151. case PIX_FMT_YUV444P10:
  152. case PIX_FMT_YUV420P16:
  153. case PIX_FMT_YUV422P16:
  154. case PIX_FMT_YUV444P16:
  155. width *= 2;
  156. break;
  157. default:
  158. av_log(s, AV_LOG_ERROR, "The pixel format '%s' is not supported.\n",
  159. av_get_pix_fmt_name(st->codec->pix_fmt));
  160. return AVERROR(EINVAL);
  161. }
  162. for (i = 0; i < height; i++) {
  163. avio_write(pb, ptr, width);
  164. ptr += picture->linesize[0];
  165. }
  166. if (st->codec->pix_fmt != PIX_FMT_GRAY8 &&
  167. st->codec->pix_fmt != PIX_FMT_GRAY16) {
  168. // Adjust for smaller Cb and Cr planes
  169. avcodec_get_chroma_sub_sample(st->codec->pix_fmt, &h_chroma_shift,
  170. &v_chroma_shift);
  171. width >>= h_chroma_shift;
  172. height >>= v_chroma_shift;
  173. ptr1 = picture->data[1];
  174. ptr2 = picture->data[2];
  175. for (i = 0; i < height; i++) { /* Cb */
  176. avio_write(pb, ptr1, width);
  177. ptr1 += picture->linesize[1];
  178. }
  179. for (i = 0; i < height; i++) { /* Cr */
  180. avio_write(pb, ptr2, width);
  181. ptr2 += picture->linesize[2];
  182. }
  183. }
  184. avio_flush(pb);
  185. return 0;
  186. }
  187. static int yuv4_write_header(AVFormatContext *s)
  188. {
  189. int *first_pkt = s->priv_data;
  190. if (s->nb_streams != 1)
  191. return AVERROR(EIO);
  192. if (s->streams[0]->codec->codec_id != AV_CODEC_ID_RAWVIDEO) {
  193. av_log(s, AV_LOG_ERROR,
  194. "A non-rawvideo stream was selected, but yuv4mpeg only handles rawvideo streams\n");
  195. return AVERROR(EINVAL);
  196. }
  197. switch (s->streams[0]->codec->pix_fmt) {
  198. case PIX_FMT_YUV411P:
  199. av_log(s, AV_LOG_WARNING, "Warning: generating rarely used 4:1:1 YUV "
  200. "stream, some mjpegtools might not work.\n");
  201. break;
  202. case PIX_FMT_GRAY8:
  203. case PIX_FMT_GRAY16:
  204. case PIX_FMT_YUV420P:
  205. case PIX_FMT_YUV422P:
  206. case PIX_FMT_YUV444P:
  207. break;
  208. case PIX_FMT_YUV420P9:
  209. case PIX_FMT_YUV422P9:
  210. case PIX_FMT_YUV444P9:
  211. case PIX_FMT_YUV420P10:
  212. case PIX_FMT_YUV422P10:
  213. case PIX_FMT_YUV444P10:
  214. case PIX_FMT_YUV420P16:
  215. case PIX_FMT_YUV422P16:
  216. case PIX_FMT_YUV444P16:
  217. if (s->streams[0]->codec->strict_std_compliance >= FF_COMPLIANCE_NORMAL) {
  218. av_log(s, AV_LOG_ERROR, "'%s' is not a official yuv4mpegpipe pixel format. "
  219. "Use '-strict -1' to encode to this pixel format.\n",
  220. av_get_pix_fmt_name(s->streams[0]->codec->pix_fmt));
  221. return AVERROR(EINVAL);
  222. }
  223. av_log(s, AV_LOG_WARNING, "Warning: generating non standart YUV stream. "
  224. "Mjpegtools will not work.\n");
  225. break;
  226. default:
  227. av_log(s, AV_LOG_ERROR, "ERROR: yuv4mpeg can only handle "
  228. "yuv444p, yuv422p, yuv420p, yuv411p and gray8 pixel formats. "
  229. "And using 'strict -1' also yuv444p9, yuv422p9, yuv420p9, "
  230. "yuv444p10, yuv422p10, yuv420p10, "
  231. "yuv444p16, yuv422p16, yuv420p16 "
  232. "and gray16 pixel formats. "
  233. "Use -pix_fmt to select one.\n");
  234. return AVERROR(EIO);
  235. }
  236. *first_pkt = 1;
  237. return 0;
  238. }
  239. AVOutputFormat ff_yuv4mpegpipe_muxer = {
  240. .name = "yuv4mpegpipe",
  241. .long_name = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe"),
  242. .extensions = "y4m",
  243. .priv_data_size = sizeof(int),
  244. .audio_codec = AV_CODEC_ID_NONE,
  245. .video_codec = AV_CODEC_ID_RAWVIDEO,
  246. .write_header = yuv4_write_header,
  247. .write_packet = yuv4_write_packet,
  248. .flags = AVFMT_RAWPICTURE,
  249. };
  250. #endif
  251. /* Header size increased to allow room for optional flags */
  252. #define MAX_YUV4_HEADER 80
  253. #define MAX_FRAME_HEADER 80
  254. static int yuv4_read_header(AVFormatContext *s)
  255. {
  256. char header[MAX_YUV4_HEADER + 10]; // Include headroom for
  257. // the longest option
  258. char *tokstart, *tokend, *header_end;
  259. int i;
  260. AVIOContext *pb = s->pb;
  261. int width = -1, height = -1, raten = 0,
  262. rated = 0, aspectn = 0, aspectd = 0;
  263. enum PixelFormat pix_fmt = PIX_FMT_NONE, alt_pix_fmt = PIX_FMT_NONE;
  264. enum AVChromaLocation chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED;
  265. AVStream *st;
  266. struct frame_attributes *s1 = s->priv_data;
  267. for (i = 0; i < MAX_YUV4_HEADER; i++) {
  268. header[i] = avio_r8(pb);
  269. if (header[i] == '\n') {
  270. header[i + 1] = 0x20; // Add a space after last option.
  271. // Makes parsing "444" vs "444alpha" easier.
  272. header[i + 2] = 0;
  273. break;
  274. }
  275. }
  276. if (i == MAX_YUV4_HEADER)
  277. return -1;
  278. if (strncmp(header, Y4M_MAGIC, strlen(Y4M_MAGIC)))
  279. return -1;
  280. s1->interlaced_frame = 0;
  281. s1->top_field_first = 0;
  282. header_end = &header[i + 1]; // Include space
  283. for (tokstart = &header[strlen(Y4M_MAGIC) + 1];
  284. tokstart < header_end; tokstart++) {
  285. if (*tokstart == 0x20)
  286. continue;
  287. switch (*tokstart++) {
  288. case 'W': // Width. Required.
  289. width = strtol(tokstart, &tokend, 10);
  290. tokstart = tokend;
  291. break;
  292. case 'H': // Height. Required.
  293. height = strtol(tokstart, &tokend, 10);
  294. tokstart = tokend;
  295. break;
  296. case 'C': // Color space
  297. if (strncmp("420jpeg", tokstart, 7) == 0) {
  298. pix_fmt = PIX_FMT_YUV420P;
  299. chroma_sample_location = AVCHROMA_LOC_CENTER;
  300. } else if (strncmp("420mpeg2", tokstart, 8) == 0) {
  301. pix_fmt = PIX_FMT_YUV420P;
  302. chroma_sample_location = AVCHROMA_LOC_LEFT;
  303. } else if (strncmp("420paldv", tokstart, 8) == 0) {
  304. pix_fmt = PIX_FMT_YUV420P;
  305. chroma_sample_location = AVCHROMA_LOC_TOPLEFT;
  306. } else if (strncmp("420p16", tokstart, 6) == 0) {
  307. pix_fmt = PIX_FMT_YUV420P16;
  308. } else if (strncmp("422p16", tokstart, 6) == 0) {
  309. pix_fmt = PIX_FMT_YUV422P16;
  310. } else if (strncmp("444p16", tokstart, 6) == 0) {
  311. pix_fmt = PIX_FMT_YUV444P16;
  312. } else if (strncmp("420p10", tokstart, 6) == 0) {
  313. pix_fmt = PIX_FMT_YUV420P10;
  314. } else if (strncmp("422p10", tokstart, 6) == 0) {
  315. pix_fmt = PIX_FMT_YUV422P10;
  316. } else if (strncmp("444p10", tokstart, 6) == 0) {
  317. pix_fmt = PIX_FMT_YUV444P10;
  318. } else if (strncmp("420p9", tokstart, 5) == 0) {
  319. pix_fmt = PIX_FMT_YUV420P9;
  320. } else if (strncmp("422p9", tokstart, 5) == 0) {
  321. pix_fmt = PIX_FMT_YUV422P9;
  322. } else if (strncmp("444p9", tokstart, 5) == 0) {
  323. pix_fmt = PIX_FMT_YUV444P9;
  324. } else if (strncmp("420", tokstart, 3) == 0) {
  325. pix_fmt = PIX_FMT_YUV420P;
  326. chroma_sample_location = AVCHROMA_LOC_CENTER;
  327. } else if (strncmp("411", tokstart, 3) == 0) {
  328. pix_fmt = PIX_FMT_YUV411P;
  329. } else if (strncmp("422", tokstart, 3) == 0) {
  330. pix_fmt = PIX_FMT_YUV422P;
  331. } else if (strncmp("444alpha", tokstart, 8) == 0 ) {
  332. av_log(s, AV_LOG_ERROR, "Cannot handle 4:4:4:4 "
  333. "YUV4MPEG stream.\n");
  334. return -1;
  335. } else if (strncmp("444", tokstart, 3) == 0) {
  336. pix_fmt = PIX_FMT_YUV444P;
  337. } else if (strncmp("mono16", tokstart, 6) == 0) {
  338. pix_fmt = PIX_FMT_GRAY16;
  339. } else if (strncmp("mono", tokstart, 4) == 0) {
  340. pix_fmt = PIX_FMT_GRAY8;
  341. } else {
  342. av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains an unknown "
  343. "pixel format.\n");
  344. return -1;
  345. }
  346. while (tokstart < header_end && *tokstart != 0x20)
  347. tokstart++;
  348. break;
  349. case 'I': // Interlace type
  350. switch (*tokstart++){
  351. case '?':
  352. break;
  353. case 'p':
  354. s1->interlaced_frame = 0;
  355. break;
  356. case 't':
  357. s1->interlaced_frame = 1;
  358. s1->top_field_first = 1;
  359. break;
  360. case 'b':
  361. s1->interlaced_frame = 1;
  362. s1->top_field_first = 0;
  363. break;
  364. case 'm':
  365. av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains mixed "
  366. "interlaced and non-interlaced frames.\n");
  367. return -1;
  368. default:
  369. av_log(s, AV_LOG_ERROR, "YUV4MPEG has invalid header.\n");
  370. return -1;
  371. }
  372. break;
  373. case 'F': // Frame rate
  374. sscanf(tokstart, "%d:%d", &raten, &rated); // 0:0 if unknown
  375. while (tokstart < header_end && *tokstart != 0x20)
  376. tokstart++;
  377. break;
  378. case 'A': // Pixel aspect
  379. sscanf(tokstart, "%d:%d", &aspectn, &aspectd); // 0:0 if unknown
  380. while (tokstart < header_end && *tokstart != 0x20)
  381. tokstart++;
  382. break;
  383. case 'X': // Vendor extensions
  384. if (strncmp("YSCSS=", tokstart, 6) == 0) {
  385. // Older nonstandard pixel format representation
  386. tokstart += 6;
  387. if (strncmp("420JPEG", tokstart, 7) == 0)
  388. alt_pix_fmt = PIX_FMT_YUV420P;
  389. else if (strncmp("420MPEG2", tokstart, 8) == 0)
  390. alt_pix_fmt = PIX_FMT_YUV420P;
  391. else if (strncmp("420PALDV", tokstart, 8) == 0)
  392. alt_pix_fmt = PIX_FMT_YUV420P;
  393. else if (strncmp("420P9", tokstart, 5) == 0)
  394. alt_pix_fmt = PIX_FMT_YUV420P9;
  395. else if (strncmp("422P9", tokstart, 5) == 0)
  396. alt_pix_fmt = PIX_FMT_YUV422P9;
  397. else if (strncmp("444P9", tokstart, 5) == 0)
  398. alt_pix_fmt = PIX_FMT_YUV444P9;
  399. else if (strncmp("420P10", tokstart, 6) == 0)
  400. alt_pix_fmt = PIX_FMT_YUV420P10;
  401. else if (strncmp("422P10", tokstart, 6) == 0)
  402. alt_pix_fmt = PIX_FMT_YUV422P10;
  403. else if (strncmp("444P10", tokstart, 6) == 0)
  404. alt_pix_fmt = PIX_FMT_YUV444P10;
  405. else if (strncmp("420P16", tokstart, 6) == 0)
  406. alt_pix_fmt = PIX_FMT_YUV420P16;
  407. else if (strncmp("422P16", tokstart, 6) == 0)
  408. alt_pix_fmt = PIX_FMT_YUV422P16;
  409. else if (strncmp("444P16", tokstart, 6) == 0)
  410. alt_pix_fmt = PIX_FMT_YUV444P16;
  411. else if (strncmp("411", tokstart, 3) == 0)
  412. alt_pix_fmt = PIX_FMT_YUV411P;
  413. else if (strncmp("422", tokstart, 3) == 0)
  414. alt_pix_fmt = PIX_FMT_YUV422P;
  415. else if (strncmp("444", tokstart, 3) == 0)
  416. alt_pix_fmt = PIX_FMT_YUV444P;
  417. }
  418. while (tokstart < header_end && *tokstart != 0x20)
  419. tokstart++;
  420. break;
  421. }
  422. }
  423. if (width == -1 || height == -1) {
  424. av_log(s, AV_LOG_ERROR, "YUV4MPEG has invalid header.\n");
  425. return -1;
  426. }
  427. if (pix_fmt == PIX_FMT_NONE) {
  428. if (alt_pix_fmt == PIX_FMT_NONE)
  429. pix_fmt = PIX_FMT_YUV420P;
  430. else
  431. pix_fmt = alt_pix_fmt;
  432. }
  433. if (raten <= 0 || rated <= 0) {
  434. // Frame rate unknown
  435. raten = 25;
  436. rated = 1;
  437. }
  438. if (aspectn == 0 && aspectd == 0) {
  439. // Pixel aspect unknown
  440. aspectd = 1;
  441. }
  442. st = avformat_new_stream(s, NULL);
  443. if (!st)
  444. return AVERROR(ENOMEM);
  445. st->codec->width = width;
  446. st->codec->height = height;
  447. av_reduce(&raten, &rated, raten, rated, (1UL << 31) - 1);
  448. avpriv_set_pts_info(st, 64, rated, raten);
  449. st->codec->pix_fmt = pix_fmt;
  450. st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
  451. st->codec->codec_id = AV_CODEC_ID_RAWVIDEO;
  452. st->sample_aspect_ratio = (AVRational){ aspectn, aspectd };
  453. st->codec->chroma_sample_location = chroma_sample_location;
  454. return 0;
  455. }
  456. static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt)
  457. {
  458. int i;
  459. char header[MAX_FRAME_HEADER+1];
  460. int packet_size, width, height;
  461. AVStream *st = s->streams[0];
  462. struct frame_attributes *s1 = s->priv_data;
  463. for (i = 0; i < MAX_FRAME_HEADER; i++) {
  464. header[i] = avio_r8(s->pb);
  465. if (header[i] == '\n') {
  466. header[i + 1] = 0;
  467. break;
  468. }
  469. }
  470. if (i == MAX_FRAME_HEADER)
  471. return -1;
  472. if (strncmp(header, Y4M_FRAME_MAGIC, strlen(Y4M_FRAME_MAGIC)))
  473. return -1;
  474. width = st->codec->width;
  475. height = st->codec->height;
  476. packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
  477. if (packet_size < 0)
  478. return -1;
  479. if (av_get_packet(s->pb, pkt, packet_size) != packet_size)
  480. return AVERROR(EIO);
  481. if (st->codec->coded_frame) {
  482. st->codec->coded_frame->interlaced_frame = s1->interlaced_frame;
  483. st->codec->coded_frame->top_field_first = s1->top_field_first;
  484. }
  485. pkt->stream_index = 0;
  486. return 0;
  487. }
  488. static int yuv4_probe(AVProbeData *pd)
  489. {
  490. /* check file header */
  491. if (strncmp(pd->buf, Y4M_MAGIC, sizeof(Y4M_MAGIC) - 1) == 0)
  492. return AVPROBE_SCORE_MAX;
  493. else
  494. return 0;
  495. }
  496. #if CONFIG_YUV4MPEGPIPE_DEMUXER
  497. AVInputFormat ff_yuv4mpegpipe_demuxer = {
  498. .name = "yuv4mpegpipe",
  499. .long_name = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe"),
  500. .priv_data_size = sizeof(struct frame_attributes),
  501. .read_probe = yuv4_probe,
  502. .read_header = yuv4_read_header,
  503. .read_packet = yuv4_read_packet,
  504. .extensions = "y4m",
  505. };
  506. #endif