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.

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