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.

945 lines
22KB

  1. /*
  2. * Image format
  3. * Copyright (c) 2000, 2001, 2002 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include "avformat.h"
  20. extern AVInputFormat pgm_iformat;
  21. extern AVOutputFormat pgm_oformat;
  22. extern AVInputFormat pgmyuv_iformat;
  23. extern AVOutputFormat pgmyuv_oformat;
  24. extern AVInputFormat ppm_iformat;
  25. extern AVOutputFormat ppm_oformat;
  26. extern AVInputFormat imgyuv_iformat;
  27. extern AVOutputFormat imgyuv_oformat;
  28. extern AVInputFormat pgmpipe_iformat;
  29. extern AVOutputFormat pgmpipe_oformat;
  30. extern AVInputFormat pgmyuvpipe_iformat;
  31. extern AVOutputFormat pgmyuvpipe_oformat;
  32. extern AVInputFormat ppmpipe_iformat;
  33. extern AVOutputFormat ppmpipe_oformat;
  34. extern AVOutputFormat yuv4mpegpipe_oformat;
  35. #define IMGFMT_YUV 1
  36. #define IMGFMT_PGMYUV 2
  37. #define IMGFMT_PGM 3
  38. #define IMGFMT_PPM 4
  39. #define IMGFMT_YUV4MPEG 5
  40. #define Y4M_MAGIC "YUV4MPEG2"
  41. #define Y4M_FRAME_MAGIC "FRAME"
  42. #define Y4M_LINE_MAX 256
  43. typedef struct {
  44. int width;
  45. int height;
  46. int img_number;
  47. int img_size;
  48. int img_fmt;
  49. int is_pipe;
  50. int header_written;
  51. char path[1024];
  52. } VideoData;
  53. static inline int pnm_space(int c)
  54. {
  55. return (c==' ' || c=='\n' || c=='\r' || c=='\t');
  56. }
  57. static void pnm_get(ByteIOContext *f, char *str, int buf_size)
  58. {
  59. char *s;
  60. int c;
  61. do {
  62. c=get_byte(f);
  63. if (c=='#') {
  64. do {
  65. c=get_byte(f);
  66. } while (c!='\n');
  67. c=get_byte(f);
  68. }
  69. } while (pnm_space(c));
  70. s=str;
  71. do {
  72. if (url_feof(f))
  73. break;
  74. if ((s - str) < buf_size - 1)
  75. *s++=c;
  76. c=get_byte(f);
  77. } while (!pnm_space(c));
  78. *s = '\0';
  79. }
  80. static int pgm_read(VideoData *s, ByteIOContext *f, UINT8 *buf, int size, int is_yuv)
  81. {
  82. int width, height, i;
  83. char buf1[32];
  84. UINT8 *picture[3];
  85. width = s->width;
  86. height = s->height;
  87. pnm_get(f, buf1, sizeof(buf1));
  88. if (strcmp(buf1, "P5")) {
  89. return -EIO;
  90. }
  91. pnm_get(f, buf1, sizeof(buf1));
  92. pnm_get(f, buf1, sizeof(buf1));
  93. pnm_get(f, buf1, sizeof(buf1));
  94. picture[0] = buf;
  95. picture[1] = buf + width * height;
  96. picture[2] = buf + width * height + (width * height / 4);
  97. get_buffer(f, picture[0], width * height);
  98. height>>=1;
  99. width>>=1;
  100. if (is_yuv) {
  101. for(i=0;i<height;i++) {
  102. get_buffer(f, picture[1] + i * width, width);
  103. get_buffer(f, picture[2] + i * width, width);
  104. }
  105. } else {
  106. for(i=0;i<height;i++) {
  107. memset(picture[1] + i * width, 128, width);
  108. memset(picture[2] + i * width, 128, width);
  109. }
  110. }
  111. return 0;
  112. }
  113. static int ppm_read(VideoData *s, ByteIOContext *f, UINT8 *buf, int size)
  114. {
  115. int width, height;
  116. char buf1[32];
  117. UINT8 *picture[3];
  118. width = s->width;
  119. height = s->height;
  120. pnm_get(f, buf1, sizeof(buf1));
  121. if (strcmp(buf1, "P6")) {
  122. return -EIO;
  123. }
  124. pnm_get(f, buf1, sizeof(buf1));
  125. pnm_get(f, buf1, sizeof(buf1));
  126. pnm_get(f, buf1, sizeof(buf1));
  127. picture[0] = buf;
  128. get_buffer(f, picture[0], width * height*3);
  129. return 0;
  130. }
  131. static int yuv_read(VideoData *s, const char *filename, UINT8 *buf, int size1)
  132. {
  133. ByteIOContext pb1, *pb = &pb1;
  134. char fname[1024], *p;
  135. int size;
  136. size = s->width * s->height;
  137. strcpy(fname, filename);
  138. p = strrchr(fname, '.');
  139. if (!p || p[1] != 'Y')
  140. return -EIO;
  141. if (url_fopen(pb, fname, URL_RDONLY) < 0)
  142. return -EIO;
  143. get_buffer(pb, buf, size);
  144. url_fclose(pb);
  145. p[1] = 'U';
  146. if (url_fopen(pb, fname, URL_RDONLY) < 0)
  147. return -EIO;
  148. get_buffer(pb, buf + size, size / 4);
  149. url_fclose(pb);
  150. p[1] = 'V';
  151. if (url_fopen(pb, fname, URL_RDONLY) < 0)
  152. return -EIO;
  153. get_buffer(pb, buf + size + (size / 4), size / 4);
  154. url_fclose(pb);
  155. return 0;
  156. }
  157. static int img_read_packet(AVFormatContext *s1, AVPacket *pkt)
  158. {
  159. VideoData *s = s1->priv_data;
  160. char filename[1024];
  161. int ret;
  162. ByteIOContext f1, *f;
  163. /*
  164. This if-statement destroys pipes - I do not see why it is necessary
  165. if (get_frame_filename(filename, sizeof(filename),
  166. s->path, s->img_number) < 0)
  167. return -EIO;
  168. */
  169. get_frame_filename(filename, sizeof(filename),
  170. s->path, s->img_number);
  171. if (!s->is_pipe) {
  172. f = &f1;
  173. if (url_fopen(f, filename, URL_RDONLY) < 0)
  174. return -EIO;
  175. } else {
  176. f = &s1->pb;
  177. if (url_feof(f))
  178. return -EIO;
  179. }
  180. av_new_packet(pkt, s->img_size);
  181. pkt->stream_index = 0;
  182. switch(s->img_fmt) {
  183. case IMGFMT_PGMYUV:
  184. ret = pgm_read(s, f, pkt->data, pkt->size, 1);
  185. break;
  186. case IMGFMT_PGM:
  187. ret = pgm_read(s, f, pkt->data, pkt->size, 0);
  188. break;
  189. case IMGFMT_YUV:
  190. ret = yuv_read(s, filename, pkt->data, pkt->size);
  191. break;
  192. case IMGFMT_PPM:
  193. ret = ppm_read(s, f, pkt->data, pkt->size);
  194. break;
  195. default:
  196. return -EIO;
  197. }
  198. if (!s->is_pipe) {
  199. url_fclose(f);
  200. }
  201. if (ret < 0) {
  202. av_free_packet(pkt);
  203. return -EIO; /* signal EOF */
  204. } else {
  205. s->img_number++;
  206. return 0;
  207. }
  208. }
  209. static int sizes[][2] = {
  210. { 640, 480 },
  211. { 720, 480 },
  212. { 720, 576 },
  213. { 352, 288 },
  214. { 352, 240 },
  215. { 160, 128 },
  216. { 512, 384 },
  217. { 640, 352 },
  218. { 640, 240 },
  219. };
  220. static int infer_size(int *width_ptr, int *height_ptr, int size)
  221. {
  222. int i;
  223. for(i=0;i<sizeof(sizes)/sizeof(sizes[0]);i++) {
  224. if ((sizes[i][0] * sizes[i][1]) == size) {
  225. *width_ptr = sizes[i][0];
  226. *height_ptr = sizes[i][1];
  227. return 0;
  228. }
  229. }
  230. return -1;
  231. }
  232. static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap)
  233. {
  234. VideoData *s = s1->priv_data;
  235. int i, h;
  236. char buf[1024];
  237. char buf1[32];
  238. ByteIOContext pb1, *f = &pb1;
  239. AVStream *st;
  240. st = av_new_stream(s1, 0);
  241. if (!st) {
  242. av_free(s);
  243. return -ENOMEM;
  244. }
  245. strcpy(s->path, s1->filename);
  246. s->img_number = 0;
  247. /* find format */
  248. if (s1->iformat->flags & AVFMT_NOFILE)
  249. s->is_pipe = 0;
  250. else
  251. s->is_pipe = 1;
  252. if (s1->iformat == &pgmyuvpipe_iformat ||
  253. s1->iformat == &pgmyuv_iformat)
  254. s->img_fmt = IMGFMT_PGMYUV;
  255. else if (s1->iformat == &pgmpipe_iformat ||
  256. s1->iformat == &pgm_iformat)
  257. s->img_fmt = IMGFMT_PGM;
  258. else if (s1->iformat == &imgyuv_iformat)
  259. s->img_fmt = IMGFMT_YUV;
  260. else if (s1->iformat == &ppmpipe_iformat ||
  261. s1->iformat == &ppm_iformat)
  262. s->img_fmt = IMGFMT_PPM;
  263. else
  264. goto fail;
  265. if (!s->is_pipe) {
  266. /* try to find the first image */
  267. for(i=0;i<5;i++) {
  268. if (get_frame_filename(buf, sizeof(buf), s->path, s->img_number) < 0)
  269. goto fail;
  270. if (url_fopen(f, buf, URL_RDONLY) >= 0)
  271. break;
  272. s->img_number++;
  273. }
  274. if (i == 5)
  275. goto fail;
  276. } else {
  277. f = &s1->pb;
  278. }
  279. /* find the image size */
  280. /* XXX: use generic file format guessing, as mpeg */
  281. switch(s->img_fmt) {
  282. case IMGFMT_PGM:
  283. case IMGFMT_PGMYUV:
  284. case IMGFMT_PPM:
  285. pnm_get(f, buf1, sizeof(buf1));
  286. pnm_get(f, buf1, sizeof(buf1));
  287. s->width = atoi(buf1);
  288. pnm_get(f, buf1, sizeof(buf1));
  289. h = atoi(buf1);
  290. if (s->img_fmt == IMGFMT_PGMYUV)
  291. h = (h * 2) / 3;
  292. s->height = h;
  293. if (s->width <= 0 ||
  294. s->height <= 0 ||
  295. (s->width % 2) != 0 ||
  296. (s->height % 2) != 0) {
  297. goto fail1;
  298. }
  299. break;
  300. case IMGFMT_YUV:
  301. /* infer size by using the file size. */
  302. {
  303. int img_size;
  304. URLContext *h;
  305. /* XXX: hack hack */
  306. h = url_fileno(f);
  307. img_size = url_seek(h, 0, SEEK_END);
  308. if (infer_size(&s->width, &s->height, img_size) < 0) {
  309. goto fail1;
  310. }
  311. }
  312. break;
  313. }
  314. if (!s->is_pipe) {
  315. url_fclose(f);
  316. } else {
  317. url_fseek(f, 0, SEEK_SET);
  318. }
  319. st->codec.codec_type = CODEC_TYPE_VIDEO;
  320. st->codec.codec_id = CODEC_ID_RAWVIDEO;
  321. st->codec.width = s->width;
  322. st->codec.height = s->height;
  323. if (s->img_fmt == IMGFMT_PPM) {
  324. st->codec.pix_fmt = PIX_FMT_RGB24;
  325. s->img_size = (s->width * s->height * 3);
  326. } else {
  327. st->codec.pix_fmt = PIX_FMT_YUV420P;
  328. s->img_size = (s->width * s->height * 3) / 2;
  329. }
  330. if (!ap || !ap->frame_rate)
  331. st->codec.frame_rate = 25 * FRAME_RATE_BASE;
  332. else
  333. st->codec.frame_rate = ap->frame_rate;
  334. return 0;
  335. fail1:
  336. if (!s->is_pipe)
  337. url_fclose(f);
  338. fail:
  339. av_free(s);
  340. return -EIO;
  341. }
  342. static int img_read_close(AVFormatContext *s1)
  343. {
  344. return 0;
  345. }
  346. /******************************************************/
  347. /* image output */
  348. static int pgm_save(AVPicture *picture, int width, int height, ByteIOContext *pb, int is_yuv)
  349. {
  350. int i, h;
  351. char buf[100];
  352. UINT8 *ptr, *ptr1, *ptr2;
  353. h = height;
  354. if (is_yuv)
  355. h = (height * 3) / 2;
  356. snprintf(buf, sizeof(buf),
  357. "P5\n%d %d\n%d\n",
  358. width, h, 255);
  359. put_buffer(pb, buf, strlen(buf));
  360. ptr = picture->data[0];
  361. for(i=0;i<height;i++) {
  362. put_buffer(pb, ptr, width);
  363. ptr += picture->linesize[0];
  364. }
  365. if (is_yuv) {
  366. height >>= 1;
  367. width >>= 1;
  368. ptr1 = picture->data[1];
  369. ptr2 = picture->data[2];
  370. for(i=0;i<height;i++) {
  371. put_buffer(pb, ptr1, width);
  372. put_buffer(pb, ptr2, width);
  373. ptr1 += picture->linesize[1];
  374. ptr2 += picture->linesize[2];
  375. }
  376. }
  377. put_flush_packet(pb);
  378. return 0;
  379. }
  380. static int ppm_save(AVPicture *picture, int width, int height, ByteIOContext *pb)
  381. {
  382. int i;
  383. char buf[100];
  384. UINT8 *ptr;
  385. snprintf(buf, sizeof(buf),
  386. "P6\n%d %d\n%d\n",
  387. width, height, 255);
  388. put_buffer(pb, buf, strlen(buf));
  389. ptr = picture->data[0];
  390. for(i=0;i<height;i++) {
  391. put_buffer(pb, ptr, width * 3);
  392. ptr += picture->linesize[0];
  393. }
  394. put_flush_packet(pb);
  395. return 0;
  396. }
  397. static int yuv_save(AVPicture *picture, int width, int height, const char *filename)
  398. {
  399. ByteIOContext pb1, *pb = &pb1;
  400. char fname[1024], *p;
  401. int i, j;
  402. UINT8 *ptr;
  403. static char *ext = "YUV";
  404. strcpy(fname, filename);
  405. p = strrchr(fname, '.');
  406. if (!p || p[1] != 'Y')
  407. return -EIO;
  408. for(i=0;i<3;i++) {
  409. if (i == 1) {
  410. width >>= 1;
  411. height >>= 1;
  412. }
  413. p[1] = ext[i];
  414. if (url_fopen(pb, fname, URL_WRONLY) < 0)
  415. return -EIO;
  416. ptr = picture->data[i];
  417. for(j=0;j<height;j++) {
  418. put_buffer(pb, ptr, width);
  419. ptr += picture->linesize[i];
  420. }
  421. put_flush_packet(pb);
  422. url_fclose(pb);
  423. }
  424. return 0;
  425. }
  426. static int yuv4mpeg_save(AVPicture *picture, int width, int height, ByteIOContext *pb, int need_stream_header,
  427. int is_yuv, int raten, int rated, int aspectn, int aspectd)
  428. {
  429. int i, n, m;
  430. char buf[Y4M_LINE_MAX+1], buf1[20];
  431. UINT8 *ptr, *ptr1, *ptr2;
  432. /* construct stream header, if this is the first frame */
  433. if(need_stream_header) {
  434. n = snprintf(buf, sizeof(buf), "%s W%d H%d F%d:%d I%s A%d:%d\n",
  435. Y4M_MAGIC,
  436. width,
  437. height,
  438. raten, rated,
  439. "p", /* ffmpeg seems to only output progressive video */
  440. aspectn, aspectd);
  441. if (n < 0) {
  442. fprintf(stderr, "Error. YUV4MPEG stream header write failed.\n");
  443. } else {
  444. fprintf(stderr, "YUV4MPEG stream header written. FPS is %d\n", raten);
  445. put_buffer(pb, buf, strlen(buf));
  446. }
  447. }
  448. /* construct frame header */
  449. m = snprintf(buf1, sizeof(buf1), "%s \n", Y4M_FRAME_MAGIC);
  450. if (m < 0) {
  451. fprintf(stderr, "Error. YUV4MPEG frame header write failed.\n");
  452. } else {
  453. /* fprintf(stderr, "YUV4MPEG frame header written.\n"); */
  454. put_buffer(pb, buf1, strlen(buf1));
  455. }
  456. ptr = picture->data[0];
  457. for(i=0;i<height;i++) {
  458. put_buffer(pb, ptr, width);
  459. ptr += picture->linesize[0];
  460. }
  461. if (is_yuv) {
  462. height >>= 1;
  463. width >>= 1;
  464. ptr1 = picture->data[1];
  465. ptr2 = picture->data[2];
  466. for(i=0;i<height;i++) { /* Cb */
  467. put_buffer(pb, ptr1, width);
  468. ptr1 += picture->linesize[1];
  469. }
  470. for(i=0;i<height;i++) { /* Cr */
  471. put_buffer(pb, ptr2, width);
  472. ptr2 += picture->linesize[2];
  473. }
  474. }
  475. put_flush_packet(pb);
  476. return 0;
  477. }
  478. static int img_write_header(AVFormatContext *s)
  479. {
  480. VideoData *img = s->priv_data;
  481. img->img_number = 1;
  482. strcpy(img->path, s->filename);
  483. /* find format */
  484. if (s->oformat->flags & AVFMT_NOFILE)
  485. img->is_pipe = 0;
  486. else
  487. img->is_pipe = 1;
  488. if (s->oformat == &pgmyuvpipe_oformat ||
  489. s->oformat == &pgmyuv_oformat) {
  490. img->img_fmt = IMGFMT_PGMYUV;
  491. } else if (s->oformat == &pgmpipe_oformat ||
  492. s->oformat == &pgm_oformat) {
  493. img->img_fmt = IMGFMT_PGM;
  494. } else if (s->oformat == &imgyuv_oformat) {
  495. img->img_fmt = IMGFMT_YUV;
  496. } else if (s->oformat == &ppmpipe_oformat ||
  497. s->oformat == &ppm_oformat) {
  498. img->img_fmt = IMGFMT_PPM;
  499. } else if (s->oformat == &yuv4mpegpipe_oformat) {
  500. img->img_fmt = IMGFMT_YUV4MPEG;
  501. img->header_written = 0;
  502. } else {
  503. goto fail;
  504. }
  505. return 0;
  506. fail:
  507. av_free(img);
  508. return -EIO;
  509. }
  510. static int img_write_packet(AVFormatContext *s, int stream_index,
  511. UINT8 *buf, int size, int force_pts)
  512. {
  513. VideoData *img = s->priv_data;
  514. AVStream *st = s->streams[stream_index];
  515. ByteIOContext pb1, *pb;
  516. AVPicture picture;
  517. int width, height, need_stream_header, ret, size1, raten, rated, aspectn, aspectd, fps, fps1;
  518. char filename[1024];
  519. width = st->codec.width;
  520. height = st->codec.height;
  521. if (img->img_number == 1) {
  522. need_stream_header = 1;
  523. } else {
  524. need_stream_header = 0;
  525. }
  526. fps = st->codec.frame_rate;
  527. fps1 = (((float)fps / FRAME_RATE_BASE) * 1000);
  528. /* Sorry about this messy code, but mpeg2enc is very picky about
  529. * the framerates it accepts. */
  530. switch(fps1) {
  531. case 23976:
  532. raten = 24000; /* turn the framerate into a ratio */
  533. rated = 1001;
  534. break;
  535. case 29970:
  536. raten = 30000;
  537. rated = 1001;
  538. break;
  539. case 25000:
  540. raten = 25;
  541. rated = 1;
  542. break;
  543. case 30000:
  544. raten = 30;
  545. rated = 1;
  546. break;
  547. case 24000:
  548. raten = 24;
  549. rated = 1;
  550. break;
  551. case 50000:
  552. raten = 50;
  553. rated = 1;
  554. break;
  555. case 59940:
  556. raten = 60000;
  557. rated = 1001;
  558. break;
  559. case 60000:
  560. raten = 60;
  561. rated = 1;
  562. break;
  563. default:
  564. raten = fps1; /* this setting should work, but often doesn't */
  565. rated = 1000;
  566. break;
  567. }
  568. aspectn = 1;
  569. aspectd = 1; /* ffmpeg always uses a 1:1 aspect ratio */
  570. switch(st->codec.pix_fmt) {
  571. case PIX_FMT_YUV420P:
  572. size1 = (width * height * 3) / 2;
  573. if (size != size1)
  574. return -EIO;
  575. picture.data[0] = buf;
  576. picture.data[1] = picture.data[0] + width * height;
  577. picture.data[2] = picture.data[1] + (width * height) / 4;
  578. picture.linesize[0] = width;
  579. picture.linesize[1] = width >> 1;
  580. picture.linesize[2] = width >> 1;
  581. break;
  582. case PIX_FMT_RGB24:
  583. size1 = (width * height * 3);
  584. if (size != size1)
  585. return -EIO;
  586. picture.data[0] = buf;
  587. picture.linesize[0] = width * 3;
  588. break;
  589. default:
  590. return -EIO;
  591. }
  592. /*
  593. This if-statement destroys pipes - I do not see why it is necessary
  594. if (get_frame_filename(filename, sizeof(filename),
  595. img->path, img->img_number) < 0)
  596. return -EIO;
  597. */
  598. get_frame_filename(filename, sizeof(filename),
  599. img->path, img->img_number);
  600. if (!img->is_pipe) {
  601. pb = &pb1;
  602. if (url_fopen(pb, filename, URL_WRONLY) < 0)
  603. return -EIO;
  604. } else {
  605. pb = &s->pb;
  606. }
  607. switch(img->img_fmt) {
  608. case IMGFMT_PGMYUV:
  609. ret = pgm_save(&picture, width, height, pb, 1);
  610. break;
  611. case IMGFMT_PGM:
  612. ret = pgm_save(&picture, width, height, pb, 0);
  613. break;
  614. case IMGFMT_YUV:
  615. ret = yuv_save(&picture, width, height, filename);
  616. break;
  617. case IMGFMT_PPM:
  618. ret = ppm_save(&picture, width, height, pb);
  619. break;
  620. case IMGFMT_YUV4MPEG:
  621. ret = yuv4mpeg_save(&picture, width, height, pb,
  622. need_stream_header, 1, raten, rated, aspectn, aspectd);
  623. break;
  624. }
  625. if (!img->is_pipe) {
  626. url_fclose(pb);
  627. }
  628. img->img_number++;
  629. return 0;
  630. }
  631. static int img_write_trailer(AVFormatContext *s)
  632. {
  633. return 0;
  634. }
  635. AVInputFormat pgm_iformat = {
  636. "pgm",
  637. "pgm image format",
  638. sizeof(VideoData),
  639. NULL,
  640. img_read_header,
  641. img_read_packet,
  642. img_read_close,
  643. NULL,
  644. AVFMT_NOFILE | AVFMT_NEEDNUMBER,
  645. .extensions = "pgm",
  646. };
  647. AVOutputFormat pgm_oformat = {
  648. "pgm",
  649. "pgm image format",
  650. "",
  651. "pgm",
  652. sizeof(VideoData),
  653. CODEC_ID_NONE,
  654. CODEC_ID_RAWVIDEO,
  655. img_write_header,
  656. img_write_packet,
  657. img_write_trailer,
  658. AVFMT_NOFILE | AVFMT_NEEDNUMBER,
  659. };
  660. AVInputFormat pgmyuv_iformat = {
  661. "pgmyuv",
  662. "pgm with YUV content image format",
  663. sizeof(VideoData),
  664. NULL, /* no probe */
  665. img_read_header,
  666. img_read_packet,
  667. img_read_close,
  668. NULL,
  669. AVFMT_NOFILE | AVFMT_NEEDNUMBER,
  670. };
  671. AVOutputFormat pgmyuv_oformat = {
  672. "pgmyuv",
  673. "pgm with YUV content image format",
  674. "",
  675. "pgm",
  676. sizeof(VideoData),
  677. CODEC_ID_NONE,
  678. CODEC_ID_RAWVIDEO,
  679. img_write_header,
  680. img_write_packet,
  681. img_write_trailer,
  682. AVFMT_NOFILE | AVFMT_NEEDNUMBER,
  683. };
  684. AVInputFormat ppm_iformat = {
  685. "ppm",
  686. "ppm image format",
  687. sizeof(VideoData),
  688. NULL,
  689. img_read_header,
  690. img_read_packet,
  691. img_read_close,
  692. NULL,
  693. AVFMT_NOFILE | AVFMT_NEEDNUMBER | AVFMT_RGB24,
  694. .extensions = "ppm",
  695. };
  696. AVOutputFormat ppm_oformat = {
  697. "ppm",
  698. "ppm image format",
  699. "",
  700. "ppm",
  701. sizeof(VideoData),
  702. CODEC_ID_NONE,
  703. CODEC_ID_RAWVIDEO,
  704. img_write_header,
  705. img_write_packet,
  706. img_write_trailer,
  707. AVFMT_NOFILE | AVFMT_NEEDNUMBER | AVFMT_RGB24,
  708. };
  709. AVInputFormat imgyuv_iformat = {
  710. ".Y.U.V",
  711. ".Y.U.V format",
  712. sizeof(VideoData),
  713. NULL,
  714. img_read_header,
  715. img_read_packet,
  716. img_read_close,
  717. NULL,
  718. AVFMT_NOFILE | AVFMT_NEEDNUMBER,
  719. .extensions = "Y",
  720. };
  721. AVOutputFormat imgyuv_oformat = {
  722. ".Y.U.V",
  723. ".Y.U.V format",
  724. "",
  725. "Y",
  726. sizeof(VideoData),
  727. CODEC_ID_NONE,
  728. CODEC_ID_RAWVIDEO,
  729. img_write_header,
  730. img_write_packet,
  731. img_write_trailer,
  732. AVFMT_NOFILE | AVFMT_NEEDNUMBER,
  733. };
  734. AVInputFormat pgmpipe_iformat = {
  735. "pgmpipe",
  736. "PGM pipe format",
  737. sizeof(VideoData),
  738. NULL, /* no probe */
  739. img_read_header,
  740. img_read_packet,
  741. img_read_close,
  742. NULL,
  743. };
  744. AVOutputFormat pgmpipe_oformat = {
  745. "pgmpipe",
  746. "PGM pipe format",
  747. "",
  748. "pgm",
  749. sizeof(VideoData),
  750. CODEC_ID_NONE,
  751. CODEC_ID_RAWVIDEO,
  752. img_write_header,
  753. img_write_packet,
  754. img_write_trailer,
  755. };
  756. AVInputFormat pgmyuvpipe_iformat = {
  757. "pgmyuvpipe",
  758. "PGM YUV pipe format",
  759. sizeof(VideoData),
  760. NULL, /* no probe */
  761. img_read_header,
  762. img_read_packet,
  763. img_read_close,
  764. NULL,
  765. };
  766. AVOutputFormat pgmyuvpipe_oformat = {
  767. "pgmyuvpipe",
  768. "PGM YUV pipe format",
  769. "",
  770. "pgm",
  771. sizeof(VideoData),
  772. CODEC_ID_NONE,
  773. CODEC_ID_RAWVIDEO,
  774. img_write_header,
  775. img_write_packet,
  776. img_write_trailer,
  777. };
  778. AVInputFormat ppmpipe_iformat = {
  779. "ppmpipe",
  780. "PPM pipe format",
  781. sizeof(VideoData),
  782. NULL, /* no probe */
  783. img_read_header,
  784. img_read_packet,
  785. img_read_close,
  786. NULL,
  787. .flags = AVFMT_RGB24,
  788. };
  789. AVOutputFormat ppmpipe_oformat = {
  790. "ppmpipe",
  791. "PPM pipe format",
  792. "",
  793. "ppm",
  794. sizeof(VideoData),
  795. CODEC_ID_NONE,
  796. CODEC_ID_RAWVIDEO,
  797. img_write_header,
  798. img_write_packet,
  799. img_write_trailer,
  800. .flags = AVFMT_RGB24,
  801. };
  802. AVOutputFormat yuv4mpegpipe_oformat = {
  803. "yuv4mpegpipe",
  804. "YUV4MPEG pipe format",
  805. "",
  806. "yuv4mpeg",
  807. sizeof(VideoData),
  808. CODEC_ID_NONE,
  809. CODEC_ID_RAWVIDEO,
  810. img_write_header,
  811. img_write_packet,
  812. img_write_trailer,
  813. };
  814. int img_init(void)
  815. {
  816. av_register_input_format(&pgm_iformat);
  817. av_register_output_format(&pgm_oformat);
  818. av_register_input_format(&pgmyuv_iformat);
  819. av_register_output_format(&pgmyuv_oformat);
  820. av_register_input_format(&ppm_iformat);
  821. av_register_output_format(&ppm_oformat);
  822. av_register_input_format(&imgyuv_iformat);
  823. av_register_output_format(&imgyuv_oformat);
  824. av_register_input_format(&pgmpipe_iformat);
  825. av_register_output_format(&pgmpipe_oformat);
  826. av_register_input_format(&pgmyuvpipe_iformat);
  827. av_register_output_format(&pgmyuvpipe_oformat);
  828. av_register_input_format(&ppmpipe_iformat);
  829. av_register_output_format(&ppmpipe_oformat);
  830. av_register_output_format(&yuv4mpegpipe_oformat);
  831. return 0;
  832. }