2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
12 /* This is a simple program that reads ivf files and decodes them
13 * using the new interface. Decoded frames are output as YV12 raw.
21 #define VPX_CODEC_DISABLE_COMPAT 1
22 #include "vpx_config.h"
23 #include "vpx/vpx_decoder.h"
24 #include "vpx_ports/vpx_timer.h"
25 #if CONFIG_VP8_DECODER || CONFIG_VP9_DECODER
26 #include "vpx/vp8dx.h"
29 #include "md5_utils.h"
31 #include "tools_common.h"
32 #include "nestegg/include/nestegg/nestegg.h"
37 #define snprintf _snprintf
38 #define isatty _isatty
39 #define fileno _fileno
49 static const char *exec_name
;
51 #define VP8_FOURCC (0x00385056)
52 #define VP9_FOURCC (0x00395056)
55 const vpx_codec_iface_t
*(*iface
)(void);
57 unsigned int fourcc_mask
;
59 #if CONFIG_VP8_DECODER
60 {"vp8", vpx_codec_vp8_dx
, VP8_FOURCC
, 0x00FFFFFF},
62 #if CONFIG_VP9_DECODER
63 {"vp9", vpx_codec_vp9_dx
, VP9_FOURCC
, 0x00FFFFFF},
68 static const arg_def_t codecarg
= ARG_DEF(NULL
, "codec", 1,
70 static const arg_def_t use_yv12
= ARG_DEF(NULL
, "yv12", 0,
71 "Output raw YV12 frames");
72 static const arg_def_t use_i420
= ARG_DEF(NULL
, "i420", 0,
73 "Output raw I420 frames");
74 static const arg_def_t flipuvarg
= ARG_DEF(NULL
, "flipuv", 0,
75 "Flip the chroma planes in the output");
76 static const arg_def_t noblitarg
= ARG_DEF(NULL
, "noblit", 0,
77 "Don't process the decoded frames");
78 static const arg_def_t progressarg
= ARG_DEF(NULL
, "progress", 0,
79 "Show progress after each frame decodes");
80 static const arg_def_t limitarg
= ARG_DEF(NULL
, "limit", 1,
81 "Stop decoding after n frames");
82 static const arg_def_t skiparg
= ARG_DEF(NULL
, "skip", 1,
83 "Skip the first n input frames");
84 static const arg_def_t postprocarg
= ARG_DEF(NULL
, "postproc", 0,
85 "Postprocess decoded frames");
86 static const arg_def_t summaryarg
= ARG_DEF(NULL
, "summary", 0,
87 "Show timing summary");
88 static const arg_def_t outputfile
= ARG_DEF("o", "output", 1,
89 "Output file name pattern (see below)");
90 static const arg_def_t threadsarg
= ARG_DEF("t", "threads", 1,
91 "Max threads to use");
92 static const arg_def_t verbosearg
= ARG_DEF("v", "verbose", 0,
93 "Show version string");
94 static const arg_def_t error_concealment
= ARG_DEF(NULL
, "error-concealment", 0,
95 "Enable decoder error-concealment");
99 static const arg_def_t md5arg
= ARG_DEF(NULL
, "md5", 0,
100 "Compute the MD5 sum of the decoded frame");
102 static const arg_def_t
*all_args
[] = {
103 &codecarg
, &use_yv12
, &use_i420
, &flipuvarg
, &noblitarg
,
104 &progressarg
, &limitarg
, &skiparg
, &postprocarg
, &summaryarg
, &outputfile
,
105 &threadsarg
, &verbosearg
,
113 #if CONFIG_VP8_DECODER
114 static const arg_def_t addnoise_level
= ARG_DEF(NULL
, "noise-level", 1,
115 "Enable VP8 postproc add noise");
116 static const arg_def_t deblock
= ARG_DEF(NULL
, "deblock", 0,
117 "Enable VP8 deblocking");
118 static const arg_def_t demacroblock_level
= ARG_DEF(NULL
, "demacroblock-level", 1,
119 "Enable VP8 demacroblocking, w/ level");
120 static const arg_def_t pp_debug_info
= ARG_DEF(NULL
, "pp-debug-info", 1,
121 "Enable VP8 visible debug info");
122 static const arg_def_t pp_disp_ref_frame
= ARG_DEF(NULL
, "pp-dbg-ref-frame", 1,
123 "Display only selected reference frame per macro block");
124 static const arg_def_t pp_disp_mb_modes
= ARG_DEF(NULL
, "pp-dbg-mb-modes", 1,
125 "Display only selected macro block modes");
126 static const arg_def_t pp_disp_b_modes
= ARG_DEF(NULL
, "pp-dbg-b-modes", 1,
127 "Display only selected block modes");
128 static const arg_def_t pp_disp_mvs
= ARG_DEF(NULL
, "pp-dbg-mvs", 1,
129 "Draw only selected motion vectors");
130 static const arg_def_t mfqe
= ARG_DEF(NULL
, "mfqe", 0,
131 "Enable multiframe quality enhancement");
133 static const arg_def_t
*vp8_pp_args
[] = {
134 &addnoise_level
, &deblock
, &demacroblock_level
, &pp_debug_info
,
135 &pp_disp_ref_frame
, &pp_disp_mb_modes
, &pp_disp_b_modes
, &pp_disp_mvs
, &mfqe
,
140 static void usage_exit() {
143 fprintf(stderr
, "Usage: %s <options> filename\n\n"
144 "Options:\n", exec_name
);
145 arg_show_usage(stderr
, all_args
);
146 #if CONFIG_VP8_DECODER
147 fprintf(stderr
, "\nVP8 Postprocessing Options:\n");
148 arg_show_usage(stderr
, vp8_pp_args
);
151 "\nOutput File Patterns:\n\n"
152 " The -o argument specifies the name of the file(s) to "
153 "write to. If the\n argument does not include any escape "
154 "characters, the output will be\n written to a single file. "
155 "Otherwise, the filename will be calculated by\n expanding "
156 "the following escape characters:\n");
158 "\n\t%%w - Frame width"
159 "\n\t%%h - Frame height"
160 "\n\t%%<n> - Frame number, zero padded to <n> places (1..9)"
161 "\n\n Pattern arguments are only supported in conjunction "
162 "with the --yv12 and\n --i420 options. If the -o option is "
163 "not specified, the output will be\n directed to stdout.\n"
165 fprintf(stderr
, "\nIncluded decoders:\n\n");
167 for (i
= 0; i
< sizeof(ifaces
) / sizeof(ifaces
[0]); i
++)
168 fprintf(stderr
, " %-6s - %s\n",
170 vpx_codec_iface_name(ifaces
[i
].iface()));
175 void die(const char *fmt
, ...) {
178 vfprintf(stderr
, fmt
, ap
);
179 fprintf(stderr
, "\n");
183 static unsigned int mem_get_le16(const void *vmem
) {
185 const unsigned char *mem
= (const unsigned char *)vmem
;
192 static unsigned int mem_get_le32(const void *vmem
) {
194 const unsigned char *mem
= (const unsigned char *)vmem
;
212 nestegg
*nestegg_ctx
;
216 unsigned int video_track
;
219 #define IVF_FRAME_HDR_SZ (sizeof(uint32_t) + sizeof(uint64_t))
220 #define RAW_FRAME_HDR_SZ (sizeof(uint32_t))
221 static int read_frame(struct input_ctx
*input
,
224 size_t *buf_alloc_sz
) {
225 char raw_hdr
[IVF_FRAME_HDR_SZ
];
227 FILE *infile
= input
->infile
;
228 enum file_kind kind
= input
->kind
;
229 if (kind
== WEBM_FILE
) {
230 if (input
->chunk
>= input
->chunks
) {
234 /* End of this packet, get another. */
236 nestegg_free_packet(input
->pkt
);
238 if (nestegg_read_packet(input
->nestegg_ctx
, &input
->pkt
) <= 0
239 || nestegg_packet_track(input
->pkt
, &track
))
242 } while (track
!= input
->video_track
);
244 if (nestegg_packet_count(input
->pkt
, &input
->chunks
))
249 if (nestegg_packet_data(input
->pkt
, input
->chunk
, buf
, buf_sz
))
255 /* For both the raw and ivf formats, the frame size is the first 4 bytes
256 * of the frame header. We just need to special case on the header
259 else if (fread(raw_hdr
, kind
== IVF_FILE
260 ? IVF_FRAME_HDR_SZ
: RAW_FRAME_HDR_SZ
, 1, infile
) != 1) {
262 fprintf(stderr
, "Failed to read frame size\n");
266 new_buf_sz
= mem_get_le32(raw_hdr
);
268 if (new_buf_sz
> 256 * 1024 * 1024) {
269 fprintf(stderr
, "Error: Read invalid frame size (%u)\n",
270 (unsigned int)new_buf_sz
);
274 if (kind
== RAW_FILE
&& new_buf_sz
> 256 * 1024)
275 fprintf(stderr
, "Warning: Read invalid frame size (%u)"
276 " - not a raw file?\n", (unsigned int)new_buf_sz
);
278 if (new_buf_sz
> *buf_alloc_sz
) {
279 uint8_t *new_buf
= realloc(*buf
, 2 * new_buf_sz
);
283 *buf_alloc_sz
= 2 * new_buf_sz
;
285 fprintf(stderr
, "Failed to allocate compressed data buffer\n");
291 *buf_sz
= new_buf_sz
;
294 if (fread(*buf
, 1, *buf_sz
, infile
) != *buf_sz
) {
295 fprintf(stderr
, "Failed to read full frame\n");
305 void *out_open(const char *out_fn
, int do_md5
) {
310 MD5Context
*md5_ctx
= out
= malloc(sizeof(MD5Context
));
315 FILE *outfile
= out
= strcmp("-", out_fn
) ? fopen(out_fn
, "wb")
316 : set_binary_mode(stdout
);
319 fprintf(stderr
, "Failed to output file");
327 void out_put(void *out
, const uint8_t *buf
, unsigned int len
, int do_md5
) {
330 MD5Update(out
, buf
, len
);
333 (void) fwrite(buf
, 1, len
, out
);
337 void out_close(void *out
, const char *out_fn
, int do_md5
) {
346 for (i
= 0; i
< 16; i
++)
347 printf("%02x", md5
[i
]);
349 printf(" %s\n", out_fn
);
356 unsigned int file_is_ivf(FILE *infile
,
357 unsigned int *fourcc
,
359 unsigned int *height
,
360 unsigned int *fps_den
,
361 unsigned int *fps_num
) {
365 if (fread(raw_hdr
, 1, 32, infile
) == 32) {
366 if (raw_hdr
[0] == 'D' && raw_hdr
[1] == 'K'
367 && raw_hdr
[2] == 'I' && raw_hdr
[3] == 'F') {
370 if (mem_get_le16(raw_hdr
+ 4) != 0)
371 fprintf(stderr
, "Error: Unrecognized IVF version! This file may not"
372 " decode properly.");
374 *fourcc
= mem_get_le32(raw_hdr
+ 8);
375 *width
= mem_get_le16(raw_hdr
+ 12);
376 *height
= mem_get_le16(raw_hdr
+ 14);
377 *fps_num
= mem_get_le32(raw_hdr
+ 16);
378 *fps_den
= mem_get_le32(raw_hdr
+ 20);
380 /* Some versions of vpxenc used 1/(2*fps) for the timebase, so
381 * we can guess the framerate using only the timebase in this
382 * case. Other files would require reading ahead to guess the
383 * timebase, like we do for webm.
385 if (*fps_num
< 1000) {
386 /* Correct for the factor of 2 applied to the timebase in the
389 if (*fps_num
& 1)*fps_den
<<= 1;
392 /* Don't know FPS for sure, and don't have readahead code
393 * (yet?), so just default to 30fps.
408 unsigned int file_is_raw(FILE *infile
,
409 unsigned int *fourcc
,
411 unsigned int *height
,
412 unsigned int *fps_den
,
413 unsigned int *fps_num
) {
414 unsigned char buf
[32];
416 vpx_codec_stream_info_t si
;
420 if (fread(buf
, 1, 32, infile
) == 32) {
423 if (mem_get_le32(buf
) < 256 * 1024 * 1024)
424 for (i
= 0; i
< sizeof(ifaces
) / sizeof(ifaces
[0]); i
++)
425 if (!vpx_codec_peek_stream_info(ifaces
[i
].iface(),
426 buf
+ 4, 32 - 4, &si
)) {
428 *fourcc
= ifaces
[i
].fourcc
;
443 nestegg_read_cb(void *buffer
, size_t length
, void *userdata
) {
446 if (fread(buffer
, 1, length
, f
) < length
) {
457 nestegg_seek_cb(int64_t offset
, int whence
, void *userdata
) {
459 case NESTEGG_SEEK_SET
:
462 case NESTEGG_SEEK_CUR
:
465 case NESTEGG_SEEK_END
:
469 return fseek(userdata
, (long)offset
, whence
) ? -1 : 0;
474 nestegg_tell_cb(void *userdata
) {
475 return ftell(userdata
);
480 nestegg_log_cb(nestegg
*context
, unsigned int severity
, char const *format
,
484 va_start(ap
, format
);
485 vfprintf(stderr
, format
, ap
);
486 fprintf(stderr
, "\n");
492 webm_guess_framerate(struct input_ctx
*input
,
493 unsigned int *fps_den
,
494 unsigned int *fps_num
) {
498 /* Guess the framerate. Read up to 1 second, or 50 video packets,
499 * whichever comes first.
501 for (i
= 0; tstamp
< 1000000000 && i
< 50;) {
505 if (nestegg_read_packet(input
->nestegg_ctx
, &pkt
) <= 0)
508 nestegg_packet_track(pkt
, &track
);
509 if (track
== input
->video_track
) {
510 nestegg_packet_tstamp(pkt
, &tstamp
);
514 nestegg_free_packet(pkt
);
517 if (nestegg_track_seek(input
->nestegg_ctx
, input
->video_track
, 0))
520 *fps_num
= (i
- 1) * 1000000;
521 *fps_den
= (unsigned int)(tstamp
/ 1000);
524 nestegg_destroy(input
->nestegg_ctx
);
525 input
->nestegg_ctx
= NULL
;
526 rewind(input
->infile
);
532 file_is_webm(struct input_ctx
*input
,
533 unsigned int *fourcc
,
535 unsigned int *height
,
536 unsigned int *fps_den
,
537 unsigned int *fps_num
) {
542 nestegg_io io
= {nestegg_read_cb
, nestegg_seek_cb
, nestegg_tell_cb
, 0};
543 nestegg_video_params params
;
545 io
.userdata
= input
->infile
;
546 if (nestegg_init(&input
->nestegg_ctx
, io
, NULL
))
549 if (nestegg_track_count(input
->nestegg_ctx
, &n
))
552 for (i
= 0; i
< n
; i
++) {
553 track_type
= nestegg_track_type(input
->nestegg_ctx
, i
);
555 if (track_type
== NESTEGG_TRACK_VIDEO
)
557 else if (track_type
< 0)
561 codec_id
= nestegg_track_codec_id(input
->nestegg_ctx
, i
);
562 if (codec_id
== NESTEGG_CODEC_VP8
) {
563 *fourcc
= VP8_FOURCC
;
564 } else if (codec_id
== NESTEGG_CODEC_VP9
) {
565 *fourcc
= VP9_FOURCC
;
567 fprintf(stderr
, "Not VPx video, quitting.\n");
571 input
->video_track
= i
;
573 if (nestegg_track_video_params(input
->nestegg_ctx
, i
, ¶ms
))
578 *width
= params
.width
;
579 *height
= params
.height
;
582 input
->nestegg_ctx
= NULL
;
583 rewind(input
->infile
);
588 void show_progress(int frame_in
, int frame_out
, unsigned long dx_time
) {
589 fprintf(stderr
, "%d decoded frames/%d showed frames in %lu us (%.2f fps)\r",
590 frame_in
, frame_out
, dx_time
,
591 (float)frame_out
* 1000000.0 / (float)dx_time
);
595 void generate_filename(const char *pattern
, char *out
, size_t q_len
,
596 unsigned int d_w
, unsigned int d_h
,
597 unsigned int frame_in
) {
598 const char *p
= pattern
;
602 char *next_pat
= strchr(p
, '%');
607 /* parse the pattern */
611 snprintf(q
, q_len
- 1, "%d", d_w
);
614 snprintf(q
, q_len
- 1, "%d", d_h
);
617 snprintf(q
, q_len
- 1, "%d", frame_in
);
620 snprintf(q
, q_len
- 1, "%02d", frame_in
);
623 snprintf(q
, q_len
- 1, "%03d", frame_in
);
626 snprintf(q
, q_len
- 1, "%04d", frame_in
);
629 snprintf(q
, q_len
- 1, "%05d", frame_in
);
632 snprintf(q
, q_len
- 1, "%06d", frame_in
);
635 snprintf(q
, q_len
- 1, "%07d", frame_in
);
638 snprintf(q
, q_len
- 1, "%08d", frame_in
);
641 snprintf(q
, q_len
- 1, "%09d", frame_in
);
644 die("Unrecognized pattern %%%c\n", p
[1]);
648 if (pat_len
>= q_len
- 1)
649 die("Output filename too long.\n");
656 /* copy the next segment */
658 copy_len
= strlen(p
);
660 copy_len
= next_pat
- p
;
662 if (copy_len
>= q_len
- 1)
663 die("Output filename too long.\n");
665 memcpy(q
, p
, copy_len
);
675 int main(int argc
, const char **argv_
) {
676 vpx_codec_ctx_t decoder
;
680 size_t buf_sz
= 0, buf_alloc_sz
= 0;
682 int frame_in
= 0, frame_out
= 0, flipuv
= 0, noblit
= 0, do_md5
= 0, progress
= 0;
683 int stop_after
= 0, postproc
= 0, summary
= 0, quiet
= 1;
686 vpx_codec_iface_t
*iface
= NULL
;
688 unsigned long dx_time
= 0;
690 char **argv
, **argi
, **argj
;
691 const char *outfile_pattern
= 0;
692 char outfile
[PATH_MAX
];
697 unsigned int fps_den
;
698 unsigned int fps_num
;
700 vpx_codec_dec_cfg_t cfg
= {0};
701 #if CONFIG_VP8_DECODER
702 vp8_postproc_cfg_t vp8_pp_cfg
= {0};
703 int vp8_dbg_color_ref_frame
= 0;
704 int vp8_dbg_color_mb_modes
= 0;
705 int vp8_dbg_color_b_modes
= 0;
706 int vp8_dbg_display_mv
= 0;
708 struct input_ctx input
= {0};
709 int frames_corrupted
= 0;
712 /* Parse command line */
713 exec_name
= argv_
[0];
714 argv
= argv_dup(argc
- 1, argv_
+ 1);
716 for (argi
= argj
= argv
; (*argj
= *argi
); argi
+= arg
.argv_step
) {
717 memset(&arg
, 0, sizeof(arg
));
720 if (arg_match(&arg
, &codecarg
, argi
)) {
723 for (j
= 0; j
< sizeof(ifaces
) / sizeof(ifaces
[0]); j
++)
724 if (!strcmp(ifaces
[j
].name
, arg
.val
))
728 iface
= ifaces
[k
].iface();
730 die("Error: Unrecognized argument (%s) to --codec\n",
732 } else if (arg_match(&arg
, &outputfile
, argi
))
733 outfile_pattern
= arg
.val
;
734 else if (arg_match(&arg
, &use_yv12
, argi
)) {
737 } else if (arg_match(&arg
, &use_i420
, argi
)) {
740 } else if (arg_match(&arg
, &flipuvarg
, argi
))
742 else if (arg_match(&arg
, &noblitarg
, argi
))
744 else if (arg_match(&arg
, &progressarg
, argi
))
746 else if (arg_match(&arg
, &limitarg
, argi
))
747 stop_after
= arg_parse_uint(&arg
);
748 else if (arg_match(&arg
, &skiparg
, argi
))
749 arg_skip
= arg_parse_uint(&arg
);
750 else if (arg_match(&arg
, &postprocarg
, argi
))
752 else if (arg_match(&arg
, &md5arg
, argi
))
754 else if (arg_match(&arg
, &summaryarg
, argi
))
756 else if (arg_match(&arg
, &threadsarg
, argi
))
757 cfg
.threads
= arg_parse_uint(&arg
);
758 else if (arg_match(&arg
, &verbosearg
, argi
))
761 #if CONFIG_VP8_DECODER
762 else if (arg_match(&arg
, &addnoise_level
, argi
)) {
764 vp8_pp_cfg
.post_proc_flag
|= VP8_ADDNOISE
;
765 vp8_pp_cfg
.noise_level
= arg_parse_uint(&arg
);
766 } else if (arg_match(&arg
, &demacroblock_level
, argi
)) {
768 vp8_pp_cfg
.post_proc_flag
|= VP8_DEMACROBLOCK
;
769 vp8_pp_cfg
.deblocking_level
= arg_parse_uint(&arg
);
770 } else if (arg_match(&arg
, &deblock
, argi
)) {
772 vp8_pp_cfg
.post_proc_flag
|= VP8_DEBLOCK
;
773 } else if (arg_match(&arg
, &mfqe
, argi
)) {
775 vp8_pp_cfg
.post_proc_flag
|= VP8_MFQE
;
776 } else if (arg_match(&arg
, &pp_debug_info
, argi
)) {
777 unsigned int level
= arg_parse_uint(&arg
);
780 vp8_pp_cfg
.post_proc_flag
&= ~0x7;
783 vp8_pp_cfg
.post_proc_flag
|= level
;
784 } else if (arg_match(&arg
, &pp_disp_ref_frame
, argi
)) {
785 unsigned int flags
= arg_parse_int(&arg
);
788 vp8_dbg_color_ref_frame
= flags
;
790 } else if (arg_match(&arg
, &pp_disp_mb_modes
, argi
)) {
791 unsigned int flags
= arg_parse_int(&arg
);
794 vp8_dbg_color_mb_modes
= flags
;
796 } else if (arg_match(&arg
, &pp_disp_b_modes
, argi
)) {
797 unsigned int flags
= arg_parse_int(&arg
);
800 vp8_dbg_color_b_modes
= flags
;
802 } else if (arg_match(&arg
, &pp_disp_mvs
, argi
)) {
803 unsigned int flags
= arg_parse_int(&arg
);
806 vp8_dbg_display_mv
= flags
;
808 } else if (arg_match(&arg
, &error_concealment
, argi
)) {
817 /* Check for unrecognized options */
818 for (argi
= argv
; *argi
; argi
++)
819 if (argi
[0][0] == '-' && strlen(argi
[0]) > 1)
820 die("Error: Unrecognized option %s\n", *argi
);
822 /* Handle non-option arguments */
829 infile
= strcmp(fn
, "-") ? fopen(fn
, "rb") : set_binary_mode(stdin
);
832 fprintf(stderr
, "Failed to open file '%s'",
833 strcmp(fn
, "-") ? fn
: "stdin");
836 #if CONFIG_OS_SUPPORT
837 /* Make sure we don't dump to the terminal, unless forced to with -o - */
838 if (!outfile_pattern
&& isatty(fileno(stdout
)) && !do_md5
&& !noblit
) {
840 "Not dumping raw video to your terminal. Use '-o -' to "
845 input
.infile
= infile
;
846 if (file_is_ivf(infile
, &fourcc
, &width
, &height
, &fps_den
,
848 input
.kind
= IVF_FILE
;
849 else if (file_is_webm(&input
, &fourcc
, &width
, &height
, &fps_den
, &fps_num
))
850 input
.kind
= WEBM_FILE
;
851 else if (file_is_raw(infile
, &fourcc
, &width
, &height
, &fps_den
, &fps_num
))
852 input
.kind
= RAW_FILE
;
854 fprintf(stderr
, "Unrecognized input file type.\n");
858 /* If the output file is not set or doesn't have a sequence number in
859 * it, then we only open it once.
861 outfile_pattern
= outfile_pattern
? outfile_pattern
: "-";
864 const char *p
= outfile_pattern
;
867 if (p
&& p
[1] >= '1' && p
[1] <= '9') {
868 /* pattern contains sequence number, so it's not unique. */
877 if (single_file
&& !noblit
) {
878 generate_filename(outfile_pattern
, outfile
, sizeof(outfile
) - 1,
880 out
= out_open(outfile
, do_md5
);
883 if (use_y4m
&& !noblit
) {
886 fprintf(stderr
, "YUV4MPEG2 not supported with output patterns,"
887 " try --i420 or --yv12.\n");
891 if (input
.kind
== WEBM_FILE
)
892 if (webm_guess_framerate(&input
, &fps_den
, &fps_num
)) {
893 fprintf(stderr
, "Failed to guess framerate -- error parsing "
899 /*Note: We can't output an aspect ratio here because IVF doesn't
900 store one, and neither does VP8.
901 That will have to wait until these tools support WebM natively.*/
902 sprintf(buffer
, "YUV4MPEG2 C%s W%u H%u F%u:%u I%c\n",
903 "420jpeg", width
, height
, fps_num
, fps_den
, 'p');
904 out_put(out
, (unsigned char *)buffer
,
905 (unsigned int)strlen(buffer
), do_md5
);
908 /* Try to determine the codec from the fourcc. */
909 for (i
= 0; i
< sizeof(ifaces
) / sizeof(ifaces
[0]); i
++)
910 if ((fourcc
& ifaces
[i
].fourcc_mask
) == ifaces
[i
].fourcc
) {
911 vpx_codec_iface_t
*ivf_iface
= ifaces
[i
].iface();
913 if (iface
&& iface
!= ivf_iface
)
914 fprintf(stderr
, "Notice -- IVF header indicates codec: %s\n",
922 dec_flags
= (postproc
? VPX_CODEC_USE_POSTPROC
: 0) |
923 (ec_enabled
? VPX_CODEC_USE_ERROR_CONCEALMENT
: 0);
924 if (vpx_codec_dec_init(&decoder
, iface
? iface
: ifaces
[0].iface(), &cfg
,
926 fprintf(stderr
, "Failed to initialize decoder: %s\n", vpx_codec_error(&decoder
));
931 fprintf(stderr
, "%s\n", decoder
.name
);
933 #if CONFIG_VP8_DECODER
935 if (vp8_pp_cfg
.post_proc_flag
936 && vpx_codec_control(&decoder
, VP8_SET_POSTPROC
, &vp8_pp_cfg
)) {
937 fprintf(stderr
, "Failed to configure postproc: %s\n", vpx_codec_error(&decoder
));
941 if (vp8_dbg_color_ref_frame
942 && vpx_codec_control(&decoder
, VP8_SET_DBG_COLOR_REF_FRAME
, vp8_dbg_color_ref_frame
)) {
943 fprintf(stderr
, "Failed to configure reference block visualizer: %s\n", vpx_codec_error(&decoder
));
947 if (vp8_dbg_color_mb_modes
948 && vpx_codec_control(&decoder
, VP8_SET_DBG_COLOR_MB_MODES
, vp8_dbg_color_mb_modes
)) {
949 fprintf(stderr
, "Failed to configure macro block visualizer: %s\n", vpx_codec_error(&decoder
));
953 if (vp8_dbg_color_b_modes
954 && vpx_codec_control(&decoder
, VP8_SET_DBG_COLOR_B_MODES
, vp8_dbg_color_b_modes
)) {
955 fprintf(stderr
, "Failed to configure block visualizer: %s\n", vpx_codec_error(&decoder
));
959 if (vp8_dbg_display_mv
960 && vpx_codec_control(&decoder
, VP8_SET_DBG_DISPLAY_MV
, vp8_dbg_display_mv
)) {
961 fprintf(stderr
, "Failed to configure motion vector visualizer: %s\n", vpx_codec_error(&decoder
));
968 fprintf(stderr
, "Skiping first %d frames.\n", arg_skip
);
970 if (read_frame(&input
, &buf
, &buf_sz
, &buf_alloc_sz
))
976 while (!read_frame(&input
, &buf
, &buf_sz
, &buf_alloc_sz
)) {
977 vpx_codec_iter_t iter
= NULL
;
979 struct vpx_usec_timer timer
;
982 vpx_usec_timer_start(&timer
);
984 if (vpx_codec_decode(&decoder
, buf
, (unsigned int)buf_sz
, NULL
, 0)) {
985 const char *detail
= vpx_codec_error_detail(&decoder
);
986 fprintf(stderr
, "Failed to decode frame: %s\n", vpx_codec_error(&decoder
));
989 fprintf(stderr
, " Additional information: %s\n", detail
);
994 vpx_usec_timer_mark(&timer
);
995 dx_time
+= (unsigned int)vpx_usec_timer_elapsed(&timer
);
999 if (vpx_codec_control(&decoder
, VP8D_GET_FRAME_CORRUPTED
, &corrupted
)) {
1000 fprintf(stderr
, "Failed VP8_GET_FRAME_CORRUPTED: %s\n",
1001 vpx_codec_error(&decoder
));
1004 frames_corrupted
+= corrupted
;
1006 vpx_usec_timer_start(&timer
);
1008 if ((img
= vpx_codec_get_frame(&decoder
, &iter
)))
1011 vpx_usec_timer_mark(&timer
);
1012 dx_time
+= (unsigned int)vpx_usec_timer_elapsed(&timer
);
1015 show_progress(frame_in
, frame_out
, dx_time
);
1020 char out_fn
[PATH_MAX
];
1024 size_t len
= sizeof(out_fn
) - 1;
1027 generate_filename(outfile_pattern
, out_fn
, len
- 1,
1028 img
->d_w
, img
->d_h
, frame_in
);
1029 out
= out_open(out_fn
, do_md5
);
1031 out_put(out
, (unsigned char *)"FRAME\n", 6, do_md5
);
1033 buf
= img
->planes
[VPX_PLANE_Y
];
1035 for (y
= 0; y
< img
->d_h
; y
++) {
1036 out_put(out
, buf
, img
->d_w
, do_md5
);
1037 buf
+= img
->stride
[VPX_PLANE_Y
];
1040 buf
= img
->planes
[flipuv
? VPX_PLANE_V
: VPX_PLANE_U
];
1042 for (y
= 0; y
< (1 + img
->d_h
) / 2; y
++) {
1043 out_put(out
, buf
, (1 + img
->d_w
) / 2, do_md5
);
1044 buf
+= img
->stride
[VPX_PLANE_U
];
1047 buf
= img
->planes
[flipuv
? VPX_PLANE_U
: VPX_PLANE_V
];
1049 for (y
= 0; y
< (1 + img
->d_h
) / 2; y
++) {
1050 out_put(out
, buf
, (1 + img
->d_w
) / 2, do_md5
);
1051 buf
+= img
->stride
[VPX_PLANE_V
];
1055 out_close(out
, out_fn
, do_md5
);
1059 if (stop_after
&& frame_in
>= stop_after
)
1063 if (summary
|| progress
) {
1064 show_progress(frame_in
, frame_out
, dx_time
);
1065 fprintf(stderr
, "\n");
1068 if (frames_corrupted
)
1069 fprintf(stderr
, "WARNING: %d frames corrupted.\n", frames_corrupted
);
1073 if (vpx_codec_destroy(&decoder
)) {
1074 fprintf(stderr
, "Failed to destroy decoder: %s\n", vpx_codec_error(&decoder
));
1075 return EXIT_FAILURE
;
1078 if (single_file
&& !noblit
)
1079 out_close(out
, outfile
, do_md5
);
1081 if (input
.nestegg_ctx
)
1082 nestegg_destroy(input
.nestegg_ctx
);
1083 if (input
.kind
!= WEBM_FILE
)
1088 return frames_corrupted
? EXIT_FAILURE
: EXIT_SUCCESS
;