Next set of files converted.

--HG--
extra : convert_revision : svn%3Aeff31bef-be4a-0410-a8fe-e47997df2690/trunk%40138
issue20
tibs 2009-05-03 16:40:57 +00:00
rodzic ad059b4d61
commit 87addc998a
4 zmienionych plików z 314 dodań i 311 usunięć

Wyświetl plik

@ -36,6 +36,7 @@
#include "compat.h" #include "compat.h"
#include "bitdata_fns.h" #include "bitdata_fns.h"
#include "printing_fns.h"
static int MASK[] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; static int MASK[] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
@ -54,7 +55,7 @@ extern int build_bitdata(bitdata_p *bitdata,
bitdata_p new = malloc(SIZEOF_BITDATA); bitdata_p new = malloc(SIZEOF_BITDATA);
if (new == NULL) if (new == NULL)
{ {
fprintf(stderr,"### Unable to allocate bitdata datastructure\n"); print_err("### Unable to allocate bitdata datastructure\n");
return 1; return 1;
} }
@ -102,7 +103,7 @@ static inline int next_bit(bitdata_p bitdata)
bitdata->cur_byte += 1; bitdata->cur_byte += 1;
if (bitdata->cur_byte > (bitdata->data_len - 1)) if (bitdata->cur_byte > (bitdata->data_len - 1))
{ {
fprintf(stderr,"### No more bits to read from input stream\n"); print_err("### No more bits to read from input stream\n");
return -1; return -1;
} }
} }
@ -215,9 +216,8 @@ extern int read_exp_golomb(bitdata_p bitdata,
int err = read_bits(bitdata,leading_zero_bits,&next); int err = read_bits(bitdata,leading_zero_bits,&next);
if (err) if (err)
{ {
fprintf(stderr, fprint_err("### Unable to read ExpGolomb value - not enough bits (%d)\n",
"### Unable to read ExpGolomb value - not enough bits (%d)\n", leading_zero_bits);
leading_zero_bits);
return err; return err;
} }
*result = (int) (pow(2,leading_zero_bits) - 1 + next); *result = (int) (pow(2,leading_zero_bits) - 1 + next);
@ -238,7 +238,7 @@ extern int read_signed_exp_golomb(bitdata_p bitdata,
int err = read_exp_golomb(bitdata,&val); int err = read_exp_golomb(bitdata,&val);
if (err) if (err)
{ {
fprintf(stderr,"### Unable to read signed ExpGolomb value\n"); print_err("### Unable to read signed ExpGolomb value\n");
return err; return err;
} }
*result = (int) (pow(-1,(val+1)) * ceil(val / 2.0)); *result = (int) (pow(-1,(val+1)) * ceil(val / 2.0));

66
es2ts.c
Wyświetl plik

@ -42,6 +42,7 @@
#include "ts_fns.h" #include "ts_fns.h"
#include "tswrite_fns.h" #include "tswrite_fns.h"
#include "misc_fns.h" #include "misc_fns.h"
#include "printing_fns.h"
#include "version.h" #include "version.h"
@ -59,7 +60,7 @@ static int write_ES_unit_as_TS(TS_writer_p output,
video_pid,DEFAULT_VIDEO_STREAM_ID); video_pid,DEFAULT_VIDEO_STREAM_ID);
if (err) if (err)
{ {
fprintf(stderr,"### Error writing ES data unit\n"); print_err("### Error writing ES data unit\n");
return err; return err;
} }
else else
@ -80,13 +81,13 @@ static int transfer_data(ES_p es,
// Write out a PAT and PMT first, or our stream won't make sense // Write out a PAT and PMT first, or our stream won't make sense
if (!quiet) if (!quiet)
printf("Using transport stream id 1, PMT PID %#x, program 1 =" fprint_msg("Using transport stream id 1, PMT PID %#x, program 1 ="
" PID %#x, stream type %#x\n",pmt_pid,video_pid, " PID %#x, stream type %#x\n",pmt_pid,video_pid,
stream_type); stream_type);
err = write_TS_program_data(output,1,1,pmt_pid,video_pid,stream_type); err = write_TS_program_data(output,1,1,pmt_pid,video_pid,stream_type);
if (err) if (err)
{ {
fprintf(stderr,"### Error writing out TS program data\n"); print_err("### Error writing out TS program data\n");
return 1; return 1;
} }
@ -99,7 +100,7 @@ static int transfer_data(ES_p es,
break; break;
else if (err) else if (err)
{ {
fprintf(stderr,"### Error copying ES data units\n"); print_err("### Error copying ES data units\n");
return err; return err;
} }
count++; count++;
@ -111,7 +112,7 @@ static int transfer_data(ES_p es,
if (err) if (err)
{ {
free_ES_unit(&unit); free_ES_unit(&unit);
fprintf(stderr,"### Error copying ES data units\n"); print_err("### Error copying ES data units\n");
return err; return err;
} }
@ -121,18 +122,17 @@ static int transfer_data(ES_p es,
break; break;
} }
if (!quiet) if (!quiet)
printf("Transferred %d ES data unit%s\n",count,(count==1?"":"s")); fprint_msg("Transferred %d ES data unit%s\n",count,(count==1?"":"s"));
return 0; return 0;
} }
static void print_usage() static void print_usage()
{ {
printf( print_msg( "Usage: es2ts [switches] [<infile>] [<outfile>]\n"
"Usage: es2ts [switches] [<infile>] [<outfile>]\n" "\n"
"\n" );
);
REPORT_VERSION("es2ts"); REPORT_VERSION("es2ts");
printf( print_msg(
"\n" "\n"
" Convert an elementary video stream to H.222 transport stream.\n" " Convert an elementary video stream to H.222 transport stream.\n"
" Supports input streams conforming to MPEG-2 (H.262), MPEG-4/AVC\n" " Supports input streams conforming to MPEG-2 (H.262), MPEG-4/AVC\n"
@ -297,8 +297,8 @@ int main(int argc, char **argv)
} }
else else
{ {
fprintf(stderr,"### es2ts: " fprint_err("### es2ts: "
"Unrecognised command line switch '%s'\n",argv[ii]); "Unrecognised command line switch '%s'\n",argv[ii]);
return 1; return 1;
} }
} }
@ -306,7 +306,7 @@ int main(int argc, char **argv)
{ {
if (had_input_name && had_output_name) if (had_input_name && had_output_name)
{ {
fprintf(stderr,"### es2ts: Unexpected '%s'\n",argv[ii]); fprint_err("### es2ts: Unexpected '%s'\n",argv[ii]);
return 1; return 1;
} }
else if (had_input_name) else if (had_input_name)
@ -325,12 +325,12 @@ int main(int argc, char **argv)
if (!had_input_name) if (!had_input_name)
{ {
fprintf(stderr,"### es2ts: No input file specified\n"); print_err("### es2ts: No input file specified\n");
return 1; return 1;
} }
if (!had_output_name) if (!had_output_name)
{ {
fprintf(stderr,"### es2ts: No output file specified\n"); print_err("### es2ts: No output file specified\n");
return 1; return 1;
} }
@ -347,18 +347,18 @@ int main(int argc, char **argv)
err = open_elementary_stream(input_name,&es); err = open_elementary_stream(input_name,&es);
if (err) if (err)
{ {
fprintf(stderr,"### es2ts: " print_err("### es2ts: "
"Problem starting elementary stream - abandoning reading\n"); "Problem starting elementary stream - abandoning reading\n");
return 1; return 1;
} }
if (!quiet) if (!quiet)
printf("Reading from %s\n",(use_stdin?"<stdin>":input_name)); fprint_msg("Reading from %s\n",(use_stdin?"<stdin>":input_name));
// Decide if the input stream is H.262 or H.264 // Decide if the input stream is H.262 or H.264
if (force_stream_type || use_stdin) if (force_stream_type || use_stdin)
{ {
if (!quiet) printf("Reading input as "); if (!quiet) print_msg("Reading input as ");
} }
else else
{ {
@ -366,30 +366,30 @@ int main(int argc, char **argv)
err = decide_ES_file_video_type(es->input,FALSE,verbose,&video_type); err = decide_ES_file_video_type(es->input,FALSE,verbose,&video_type);
if (err) if (err)
{ {
fprintf(stderr,"### es2ts: Error deciding on stream type\n"); print_err("### es2ts: Error deciding on stream type\n");
close_elementary_stream(&es); close_elementary_stream(&es);
return 1; return 1;
} }
if (!quiet) printf("Input appears to be "); if (!quiet) print_msg("Input appears to be ");
} }
switch (video_type) switch (video_type)
{ {
case VIDEO_H262: case VIDEO_H262:
stream_type = MPEG2_VIDEO_STREAM_TYPE; stream_type = MPEG2_VIDEO_STREAM_TYPE;
if (!quiet) printf("MPEG-2 (H.262)\n"); if (!quiet) print_msg("MPEG-2 (H.262)\n");
break; break;
case VIDEO_H264: case VIDEO_H264:
stream_type = AVC_VIDEO_STREAM_TYPE; stream_type = AVC_VIDEO_STREAM_TYPE;
if (!quiet) printf("MPEG-4/AVC (H.264)\n"); if (!quiet) print_msg("MPEG-4/AVC (H.264)\n");
break; break;
case VIDEO_AVS: case VIDEO_AVS:
stream_type = AVS_VIDEO_STREAM_TYPE; stream_type = AVS_VIDEO_STREAM_TYPE;
if (!quiet) printf("AVS\n"); if (!quiet) print_msg("AVS\n");
break; break;
case VIDEO_UNKNOWN: case VIDEO_UNKNOWN:
if (!quiet) printf("Unknown\n"); if (!quiet) print_msg("Unknown\n");
fprintf(stderr,"### es2ts: Input video type is not recognised\n"); print_err("### es2ts: Input video type is not recognised\n");
close_elementary_stream(&es); close_elementary_stream(&es);
return 1; return 1;
} }
@ -404,23 +404,23 @@ int main(int argc, char **argv)
if (err) if (err)
{ {
close_elementary_stream(&es); close_elementary_stream(&es);
fprintf(stderr,"### es2ts: Unable to open %s\n",output_name); fprint_err("### es2ts: Unable to open %s\n",output_name);
return 1; return 1;
} }
if (max && !quiet) if (max && !quiet)
printf("Stopping after %d ES data units\n",max); fprint_msg("Stopping after %d ES data units\n",max);
err = transfer_data(es,output,pmt_pid,video_pid,stream_type, err = transfer_data(es,output,pmt_pid,video_pid,stream_type,
max,verbose,quiet); max,verbose,quiet);
if (err) if (err)
fprintf(stderr,"### es2ts: Error transferring data\n"); print_err("### es2ts: Error transferring data\n");
close_elementary_stream(&es); // Closes the input file for us close_elementary_stream(&es); // Closes the input file for us
err2 = tswrite_close(output,quiet); err2 = tswrite_close(output,quiet);
if (err2) if (err2)
{ {
fprintf(stderr,"### es2ts: Error closing output %s: %s\n",output_name, fprint_err("### es2ts: Error closing output %s: %s\n",output_name,
strerror(errno)); strerror(errno));
return 1; return 1;
} }

341
esdots.c
Wyświetl plik

@ -47,6 +47,7 @@
#include "accessunit_fns.h" #include "accessunit_fns.h"
#include "h262_fns.h" #include "h262_fns.h"
#include "avs_fns.h" #include "avs_fns.h"
#include "printing_fns.h"
#include "misc_fns.h" #include "misc_fns.h"
#include "version.h" #include "version.h"
@ -78,13 +79,14 @@ static void h262_item_dot(h262_item_p item,
*delta_gop = (frames - temp_frames)/frame_rate; // time between two GOPs [in seconds] *delta_gop = (frames - temp_frames)/frame_rate; // time between two GOPs [in seconds]
temp_frames = frames; temp_frames = frames;
if (show_gop_time && temp_frames) if (show_gop_time && temp_frames)
printf(": %2.4fs\n", *delta_gop); fprint_msg(": %2.4fs\n", *delta_gop);
} }
if (item->unit.start_code == 0x00) if (item->unit.start_code == 0x00)
{ {
if (frames % ((int)frame_rate*60) == 0) if (frames % ((int)frame_rate*60) == 0)
printf("\n %d minute%s\n",frames/(int)(frame_rate*60),(frames/(int)(frame_rate*60)==1?"":"s")); fprint_msg("\n %d minute%s\n",frames/(int)(frame_rate*60),
(frames/(int)(frame_rate*60)==1?"":"s"));
frames++; frames++;
} }
@ -116,7 +118,7 @@ static void h262_item_dot(h262_item_p item,
} }
break; break;
} }
printf(str); print_msg(str);
fflush(stdout); fflush(stdout);
} }
@ -143,27 +145,27 @@ static int report_h262_file_as_dots(ES_p es,
double time_gop_tot = 0.0; double time_gop_tot = 0.0;
if (verbose) if (verbose)
printf("\n" print_msg("\n"
"Each character represents a single H.262 item\n" "Each character represents a single H.262 item\n"
"Pictures are represented according to their picture coding\n" "Pictures are represented according to their picture coding\n"
"type, and the slices within a picture are not shown.\n" "type, and the slices within a picture are not shown.\n"
" i means an I picture\n" " i means an I picture\n"
" p means a P picture\n" " p means a P picture\n"
" b means a B picture\n" " b means a B picture\n"
" d means a D picture (these should not occur in MPEG-2)\n" " d means a D picture (these should not occur in MPEG-2)\n"
" x means some other picture (such should not occur)\n" " x means some other picture (such should not occur)\n"
"Other items are represented as follows:\n" "Other items are represented as follows:\n"
" [ means a Sequence header\n" " [ means a Sequence header\n"
" > means a Group Start header\n" " > means a Group Start header\n"
" E means an Extension start header\n" " E means an Extension start header\n"
" U means a User data header\n" " U means a User data header\n"
" X means a Sequence Error\n" " X means a Sequence Error\n"
" ] means a Sequence End\n" " ] means a Sequence End\n"
" R means a Reserved item\n" " R means a Reserved item\n"
" ? means something else. This may indicate that the stream\n" " ? means something else. This may indicate that the stream\n"
" is not an ES representing H.262 (it might, for instance\n" " is not an ES representing H.262 (it might, for instance\n"
" be PES)\n" " be PES)\n"
"\n"); "\n");
for (;;) for (;;)
{ {
@ -173,7 +175,7 @@ static int report_h262_file_as_dots(ES_p es,
break; break;
else if (err) else if (err)
{ {
fprintf(stderr,"### Error copying NAL units\n"); print_err("### Error copying NAL units\n");
return err; return err;
} }
count++; count++;
@ -192,8 +194,8 @@ static int report_h262_file_as_dots(ES_p es,
if (max > 0 && count >= max) if (max > 0 && count >= max)
break; break;
} }
printf("\nFound %d MPEG2 item%s\n",count,(count==1?"":"s")); fprint_msg("\nFound %d MPEG2 item%s\n",count,(count==1?"":"s"));
printf("GOP times (s): max=%2.4f, min=%2.4f, mean=%2.6f (frame rate = %2.2f)\n",time_gop_max, fprint_msg("GOP times (s): max=%2.4f, min=%2.4f, mean=%2.6f (frame rate = %2.2f)\n",time_gop_max,
time_gop_min,time_gop_tot/(gops-1), frame_rate); time_gop_min,time_gop_tot/(gops-1), frame_rate);
return 0; return 0;
} }
@ -218,25 +220,25 @@ static int report_avs_file_as_dots(ES_p es,
avs_context_p context; avs_context_p context;
if (verbose) if (verbose)
printf("\n" print_msg("\n"
"Each character represents a single AVS item\n" "Each character represents a single AVS item\n"
"Frames are represented according to their picture coding\n" "Frames are represented according to their picture coding\n"
"type, and the slices within a frame are not shown.\n" "type, and the slices within a frame are not shown.\n"
" i means an I frame\n" " i means an I frame\n"
" p means a P frame\n" " p means a P frame\n"
" b means a B frame\n" " b means a B frame\n"
" _ means a (stray) slice, normally only at the start of a stream\n" " _ means a (stray) slice, normally only at the start of a stream\n"
" ! means something else (this should not be possible)\n" " ! means something else (this should not be possible)\n"
"Other items are represented as follows:\n" "Other items are represented as follows:\n"
" [ means a Sequence header\n" " [ means a Sequence header\n"
" E means an Extension start header\n" " E means an Extension start header\n"
" U means a User data header\n" " U means a User data header\n"
" ] means a Sequence End\n" " ] means a Sequence End\n"
" V means a Video edit item\n" " V means a Video edit item\n"
" ? means something else. This may indicate that the stream\n" " ? means something else. This may indicate that the stream\n"
" is not an ES representing AVS (it might, for instance\n" " is not an ES representing AVS (it might, for instance\n"
" be PES)\n" " be PES)\n"
"\n"); "\n");
err = build_avs_context(es,&context); err = build_avs_context(es,&context);
if (err) return err; if (err) return err;
@ -258,32 +260,32 @@ static int report_avs_file_as_dots(ES_p es,
{ {
frames ++; frames ++;
if (avs_frame->picture_coding_type == AVS_I_PICTURE_CODING) if (avs_frame->picture_coding_type == AVS_I_PICTURE_CODING)
printf("i"); print_msg("i");
else if (avs_frame->picture_coding_type == AVS_P_PICTURE_CODING) else if (avs_frame->picture_coding_type == AVS_P_PICTURE_CODING)
printf("p"); print_msg("p");
else if (avs_frame->picture_coding_type == AVS_B_PICTURE_CODING) else if (avs_frame->picture_coding_type == AVS_B_PICTURE_CODING)
printf("b"); print_msg("b");
else else
printf("!"); print_msg("!");
// Give a *rough* guide as to timing -- assume a constant frame rate // Give a *rough* guide as to timing -- assume a constant frame rate
if (frames % (int)(frame_rate*60) == 0) if (frames % (int)(frame_rate*60) == 0)
printf("\n%d minute%s\n",frames/(25*60),(frames/(25*60)==1?"":"s")); fprint_msg("\n%d minute%s\n",frames/(25*60),(frames/(25*60)==1?"":"s"));
} }
else if (avs_frame->start_code < 0xB0) else if (avs_frame->start_code < 0xB0)
printf("_"); // slice -- shouldn't happen print_msg("_"); // slice -- shouldn't happen
else else
{ {
switch (avs_frame->start_code) switch (avs_frame->start_code)
{ {
case 0xB0: // sequence header case 0xB0: // sequence header
frame_rate = avs_frame_rate(avs_frame->frame_rate_code); frame_rate = avs_frame_rate(avs_frame->frame_rate_code);
printf("["); print_msg("[");
break; break;
case 0xB1: printf("]"); break; case 0xB1: print_msg("]"); break;
case 0xB2: printf("U"); break; case 0xB2: print_msg("U"); break;
case 0xB5: printf("E"); break; case 0xB5: print_msg("E"); break;
case 0xB7: printf("V"); break; case 0xB7: print_msg("V"); break;
default: /*printf("?");*/ printf("<%x>",avs_frame->start_code); break; default: /*print_msg("?");*/ fprint_msg("<%x>",avs_frame->start_code); break;
} }
} }
@ -293,13 +295,13 @@ static int report_avs_file_as_dots(ES_p es,
if (max > 0 && frames >= max) if (max > 0 && frames >= max)
{ {
printf("\nStopping because %d frames have been read\n",frames); fprint_msg("\nStopping because %d frames have been read\n",frames);
break; break;
} }
} }
printf("\nFound %d frame%s in %d AVS item%s\n", fprint_msg("\nFound %d frame%s in %d AVS item%s\n",
frames,(frames==1?"":"s"),count,(count==1?"":"s")); frames,(frames==1?"":"s"),count,(count==1?"":"s"));
free_avs_context(&context); free_avs_context(&context);
return 0; return 0;
} }
@ -320,7 +322,7 @@ static char choose_nal_type(access_unit_p access_unit, int *gop_start_found)
// The value recovery_frame_cnt is never considered (as if it was 0). // The value recovery_frame_cnt is never considered (as if it was 0).
if (access_unit->primary_start == NULL) if (access_unit->primary_start == NULL)
printf("_"); print_msg("_");
else if (access_unit->primary_start->nal_ref_idc == 0) else if (access_unit->primary_start->nal_ref_idc == 0)
{ {
if (all_slices_I(access_unit)) if (all_slices_I(access_unit))
@ -360,8 +362,8 @@ static char choose_nal_type(access_unit_p access_unit, int *gop_start_found)
// recovery point. This is technically legal but not supported // recovery point. This is technically legal but not supported
// in our research of random access point. // in our research of random access point.
if (temp_nal_unit->u.sei_recovery.recovery_frame_cnt != 0) if (temp_nal_unit->u.sei_recovery.recovery_frame_cnt != 0)
printf("!!! recovery_frame_cnt = %d\n", fprint_msg("!!! recovery_frame_cnt = %d\n",
temp_nal_unit->u.sei_recovery.recovery_frame_cnt); temp_nal_unit->u.sei_recovery.recovery_frame_cnt);
} }
} }
} }
@ -405,22 +407,22 @@ static int dots_by_access_unit(ES_p es,
char char_nal_type = 'a'; char char_nal_type = 'a';
if (verbose) if (verbose)
printf("\n" print_msg("\n"
"Each character represents a single access unit\n" "Each character represents a single access unit\n"
"\n" "\n"
" D means an IDR.\n" " D means an IDR.\n"
" d means an IDR that is not all I slices.\n" " d means an IDR that is not all I slices.\n"
" I, P, B means all slices of the primary picture are I, P or B,\n" " I, P, B means all slices of the primary picture are I, P or B,\n"
" and this is a reference picture.\n" " and this is a reference picture.\n"
" i, p, b means all slices of the primary picture are I, P or B,\n" " i, p, b means all slices of the primary picture are I, P or B,\n"
" and this is NOT a reference picture.\n" " and this is NOT a reference picture.\n"
" X or x means that not all slices are of the same type.\n" " X or x means that not all slices are of the same type.\n"
" ? means some other type of access unit.\n" " ? means some other type of access unit.\n"
" _ means that the access unit doesn't contain a primary picture.\n" " _ means that the access unit doesn't contain a primary picture.\n"
"\n" "\n"
"If -hasheos was specified:\n" "If -hasheos was specified:\n"
" # means an EOS (end-of-stream) NAL unit.\n" " # means an EOS (end-of-stream) NAL unit.\n"
"\n"); "\n");
err = build_access_unit_context(es,&context); err = build_access_unit_context(es,&context);
if (err) return err; if (err) return err;
@ -454,15 +456,16 @@ static int dots_by_access_unit(ES_p es,
size_gop_tot += size_gop; size_gop_tot += size_gop;
gops++; gops++;
if (show_gop_time) if (show_gop_time)
printf(": %2.4f\n", (double)size_gop/frame_rate ); // that's the time duration of a "GOP" fprint_msg(": %2.4f\n",
// (if the frame rate is 25fps) (double)size_gop/frame_rate ); // that's the time duration of a "GOP"
// (if the frame rate is 25fps)
} }
is_first_k_frame = FALSE; is_first_k_frame = FALSE;
k_frame = access_unit_count; k_frame = access_unit_count;
} }
printf("%c", char_nal_type); fprint_msg("%c", char_nal_type);
access_unit_count++; access_unit_count++;
fflush(stdout); fflush(stdout);
free_access_unit(&access_unit); free_access_unit(&access_unit);
@ -472,33 +475,33 @@ static int dots_by_access_unit(ES_p es,
{ {
if (hash_eos) if (hash_eos)
{ {
printf("#"); print_msg("#");
// This should be enough to allow us to keep on after the EOS // This should be enough to allow us to keep on after the EOS
context->end_of_stream = FALSE; context->end_of_stream = FALSE;
context->no_more_data = FALSE; context->no_more_data = FALSE;
} }
else else
{ {
printf("\nStopping because found end-of-stream NAL unit\n"); print_msg("\nStopping because found end-of-stream NAL unit\n");
break; break;
} }
} }
if (max > 0 && context->nac->count >= max) if (max > 0 && context->nac->count >= max)
{ {
printf("\nStopping because %d NAL units have been read\n", fprint_msg("\nStopping because %d NAL units have been read\n",
context->nac->count); context->nac->count);
break; break;
} }
} }
printf("\nFound %d NAL unit%s in %d access unit%s\n", fprint_msg("\nFound %d NAL unit%s in %d access unit%s\n",
context->nac->count,(context->nac->count==1?"":"s"), context->nac->count,(context->nac->count==1?"":"s"),
access_unit_count,(access_unit_count==1?"":"s")); access_unit_count,(access_unit_count==1?"":"s"));
if (gops) //only if there is more than 1 gop if (gops) //only if there is more than 1 gop
printf("GOP size (s): max=%2.4f, min=%2.4f, mean=%2.5f (frame rate = %2.2f)\n", fprint_msg("GOP size (s): max=%2.4f, min=%2.4f, mean=%2.5f (frame rate = %2.2f)\n",
(double)size_gop_max/frame_rate, (double)size_gop_min/frame_rate, (double)size_gop_max/frame_rate, (double)size_gop_min/frame_rate,
(double)size_gop_tot/(frame_rate*gops), frame_rate); (double)size_gop_tot/(frame_rate*gops), frame_rate);
free_access_unit_context(&context); free_access_unit_context(&context);
return 0; return 0;
} }
@ -527,53 +530,53 @@ static int report_file_as_ES_dots(ES_p es,
if (verbose) if (verbose)
{ {
printf("\n" print_msg("\n"
"Each character represents a single ES unit\n"); "Each character represents a single ES unit\n");
switch (what_data) switch (what_data)
{ {
case VIDEO_H262: case VIDEO_H262:
printf("Pictures are represented according to their picture coding\n" print_msg("Pictures are represented according to their picture coding\n"
"type, and the slices within a picture are not shown.\n" "type, and the slices within a picture are not shown.\n"
" i means an I picture\n" " i means an I picture\n"
" p means a P picture\n" " p means a P picture\n"
" b means a B picture\n" " b means a B picture\n"
" d means a D picture (these should not occur in MPEG-2)\n" " d means a D picture (these should not occur in MPEG-2)\n"
" ! means some other picture (such should not occur)\n" " ! means some other picture (such should not occur)\n"
"Other items are represented as follows:\n" "Other items are represented as follows:\n"
" [ means a Sequence header\n" " [ means a Sequence header\n"
" > means a Group Start header\n" " > means a Group Start header\n"
" E means an Extension start header\n" " E means an Extension start header\n"
" U means a User data header\n" " U means a User data header\n"
" X means a Sequence Error\n" " X means a Sequence Error\n"
" ] means a Sequence End\n" " ] means a Sequence End\n"
" R means a Reserved item\n"); " R means a Reserved item\n");
break; break;
case VIDEO_H264: case VIDEO_H264:
printf("### esdots: -es is not yet supported for H.264\n"); print_msg("### esdots: -es is not yet supported for H.264\n");
return 1; return 1;
//break; //break;
case VIDEO_AVS: case VIDEO_AVS:
printf("Frames are represented according to their picture coding\n" print_msg("Frames are represented according to their picture coding\n"
"type, and the slices within a frame are not shown.\n" "type, and the slices within a frame are not shown.\n"
" i means an I frame\n" " i means an I frame\n"
" p means a P frame\n" " p means a P frame\n"
" b means a B frame\n" " b means a B frame\n"
" _ means a slice\n" " _ means a slice\n"
" ! means something else (this should not be possible)\n" " ! means something else (this should not be possible)\n"
"Other items are represented as follows:\n" "Other items are represented as follows:\n"
" [ means a Sequence header\n" " [ means a Sequence header\n"
" E means an Extension start header\n" " E means an Extension start header\n"
" U means a User data header\n" " U means a User data header\n"
" ] means a Sequence End\n" " ] means a Sequence End\n"
" V means a Video edit item\n"); " V means a Video edit item\n");
default: default:
printf("### esdots: Unexpected type of data\n"); print_msg("### esdots: Unexpected type of data\n");
return 1; return 1;
} }
printf(" ? means something else. This may indicate that the stream\n" print_msg(" ? means something else. This may indicate that the stream\n"
" is not an ES representing AVS (it might, for instance\n" " is not an ES representing AVS (it might, for instance\n"
" be PES)\n" " be PES)\n"
"\n"); "\n");
} }
for (;;) for (;;)
@ -594,27 +597,27 @@ static int report_file_as_ES_dots(ES_p es,
picture_coding_type = (unit.data[5] & 0x38) >> 3; picture_coding_type = (unit.data[5] & 0x38) >> 3;
switch (picture_coding_type) switch (picture_coding_type)
{ {
case 1: printf("i"); break; case 1: print_msg("i"); break;
case 2: printf("p"); break; case 2: print_msg("p"); break;
case 3: printf("b"); break; case 3: print_msg("b"); break;
case 4: printf("d"); break; case 4: print_msg("d"); break;
default: printf("!"); break; default: print_msg("!"); break;
} }
break; break;
case 0xB0: printf("R"); break; // Reserved case 0xB0: print_msg("R"); break; // Reserved
case 0xB1: printf("R"); break; // Reserved case 0xB1: print_msg("R"); break; // Reserved
case 0xB2: printf("U"); break; // User data case 0xB2: print_msg("U"); break; // User data
case 0xB3: printf("["); break; // SEQUENCE HEADER case 0xB3: print_msg("["); break; // SEQUENCE HEADER
case 0xB4: printf("X"); break; // Sequence error case 0xB4: print_msg("X"); break; // Sequence error
case 0xB5: printf("E"); break; // Extension start case 0xB5: print_msg("E"); break; // Extension start
case 0xB6: printf("R"); break; // Reserved case 0xB6: print_msg("R"); break; // Reserved
case 0xB7: printf("]"); break; // SEQUENCE END case 0xB7: print_msg("]"); break; // SEQUENCE END
case 0xB8: printf(">"); break; // Group start case 0xB8: print_msg(">"); break; // Group start
default: default:
if (unit.start_code >= 0x01 && unit.start_code <= 0xAF) if (unit.start_code >= 0x01 && unit.start_code <= 0xAF)
printf("_"); print_msg("_");
else else
printf("?"); print_msg("?");
break; break;
} }
break; break;
@ -624,25 +627,25 @@ static int report_file_as_ES_dots(ES_p es,
switch (unit.start_code) switch (unit.start_code)
{ {
case 0xB3: case 0xB3:
printf("i"); break; print_msg("i"); break;
case 0xB6: case 0xB6:
switch (avs_picture_coding_type(&unit)) switch (avs_picture_coding_type(&unit))
{ {
case AVS_P_PICTURE_CODING: printf("p"); break; case AVS_P_PICTURE_CODING: print_msg("p"); break;
case AVS_B_PICTURE_CODING: printf("b"); break; case AVS_B_PICTURE_CODING: print_msg("b"); break;
default: printf("!"); break; default: print_msg("!"); break;
} }
break; break;
case 0xB0: printf("["); break; case 0xB0: print_msg("["); break;
case 0xB1: printf("]"); break; case 0xB1: print_msg("]"); break;
case 0xB2: printf("U"); break; case 0xB2: print_msg("U"); break;
case 0xB5: printf("E"); break; case 0xB5: print_msg("E"); break;
case 0xB7: printf("V"); break; case 0xB7: print_msg("V"); break;
default: default:
if (unit.start_code < 0xB0) if (unit.start_code < 0xB0)
printf("_"); print_msg("_");
else else
printf("?"); print_msg("?");
break; break;
} }
default: /* shouldn't happen */ break; default: /* shouldn't happen */ break;
@ -653,24 +656,24 @@ static int report_file_as_ES_dots(ES_p es,
if (max > 0 && count >= max) if (max > 0 && count >= max)
{ {
printf("\nStopping because %d ES units have been read\n",count); fprint_msg("\nStopping because %d ES units have been read\n",count);
break; break;
} }
} }
clear_ES_unit(&unit); clear_ES_unit(&unit);
printf("\nFound %d ES units%s\n",count,(count==1?"":"s")); fprint_msg("\nFound %d ES units%s\n",count,(count==1?"":"s"));
return 0; return 0;
} }
static void print_usage() static void print_usage()
{ {
printf( print_msg(
"Usage: esdots [switches] [<infile>]\n" "Usage: esdots [switches] [<infile>]\n"
"\n" "\n"
); );
REPORT_VERSION("esdots"); REPORT_VERSION("esdots");
printf( print_msg(
"\n" "\n"
" Present the content of an H.264 (MPEG-4/AVC), H.262 (MPEG-2) or AVS\n" " Present the content of an H.264 (MPEG-4/AVC), H.262 (MPEG-2) or AVS\n"
" elementary stream as a sequence of characters, representing access\n" " elementary stream as a sequence of characters, representing access\n"
@ -800,8 +803,8 @@ int main(int argc, char **argv)
} }
else else
{ {
fprintf(stderr,"### esdots: " fprint_err("### esdots: "
"Unrecognised command line switch '%s'\n",argv[ii]); "Unrecognised command line switch '%s'\n",argv[ii]);
return 1; return 1;
} }
} }
@ -809,7 +812,7 @@ int main(int argc, char **argv)
{ {
if (had_input_name) if (had_input_name)
{ {
fprintf(stderr,"### esdots: Unexpected '%s'\n",argv[ii]); fprint_err("### esdots: Unexpected '%s'\n",argv[ii]);
return 1; return 1;
} }
else else
@ -823,7 +826,7 @@ int main(int argc, char **argv)
if (!had_input_name) if (!had_input_name)
{ {
fprintf(stderr,"### esdots: No input file specified\n"); print_err("### esdots: No input file specified\n");
return 1; return 1;
} }
@ -831,7 +834,7 @@ int main(int argc, char **argv)
force_stream_type,want_data,&is_data,&es); force_stream_type,want_data,&is_data,&es);
if (err) if (err)
{ {
fprintf(stderr,"### esdots: Error opening input file\n"); print_err("### esdots: Error opening input file\n");
return 1; return 1;
} }
@ -845,12 +848,12 @@ int main(int argc, char **argv)
err = report_avs_file_as_dots(es,max,verbose); err = report_avs_file_as_dots(es,max,verbose);
else else
{ {
fprintf(stderr,"### esdots: Unexpected type of video data\n"); print_err("### esdots: Unexpected type of video data\n");
} }
if (err) if (err)
{ {
fprintf(stderr,"### esdots: Error producing 'dots'\n"); print_err("### esdots: Error producing 'dots'\n");
(void) close_input_as_ES(input_name,&es); (void) close_input_as_ES(input_name,&es);
return 1; return 1;
} }
@ -858,7 +861,7 @@ int main(int argc, char **argv)
err = close_input_as_ES(input_name,&es); err = close_input_as_ES(input_name,&es);
if (err) if (err)
{ {
fprintf(stderr,"### esdots: Error closing input file\n"); print_err("### esdots: Error closing input file\n");
return 1; return 1;
} }
return 0; return 0;

Wyświetl plik

@ -47,6 +47,7 @@
#include "accessunit_fns.h" #include "accessunit_fns.h"
#include "h262_fns.h" #include "h262_fns.h"
#include "misc_fns.h" #include "misc_fns.h"
#include "printing_fns.h"
#include "tswrite_fns.h" #include "tswrite_fns.h"
#include "filter_fns.h" #include "filter_fns.h"
#include "version.h" #include "version.h"
@ -94,7 +95,7 @@ static int copy_h262(ES_p es,
break; break;
else if (err) else if (err)
{ {
fprintf(stderr,"### Error copying NAL units\n"); print_err("### Error copying NAL units\n");
return err; return err;
} }
count++; count++;
@ -107,7 +108,7 @@ static int copy_h262(ES_p es,
err = write_ES_unit(output.es_output,&(item->unit)); err = write_ES_unit(output.es_output,&(item->unit));
if (err) if (err)
{ {
fprintf(stderr,"### Error writing MPEG2 item\n"); print_err("### Error writing MPEG2 item\n");
return err; return err;
} }
@ -117,7 +118,7 @@ static int copy_h262(ES_p es,
break; break;
} }
if (!quiet) if (!quiet)
printf("Copied %d MPEG2 item%s\n",count,(count==1?"":"s")); fprint_msg("Copied %d MPEG2 item%s\n",count,(count==1?"":"s"));
return 0; return 0;
} }
@ -141,7 +142,7 @@ static int write_h262_picture(WRITER output,
err = write_h262_picture_as_ES(output.es_output,picture); err = write_h262_picture_as_ES(output.es_output,picture);
if (err) if (err)
{ {
fprintf(stderr,"### Error writing out H.262 picture\n"); print_err("### Error writing out H.262 picture\n");
return err; return err;
} }
return 0; return 0;
@ -185,14 +186,14 @@ static int strip_h262(ES_p es,
err = build_h262_context(es,&h262); err = build_h262_context(es,&h262);
if (err) if (err)
{ {
fprintf(stderr,"### Unable to build H.262 picture reading context\n"); print_err("### Unable to build H.262 picture reading context\n");
return 1; return 1;
} }
err = build_h262_filter_context_strip(&fcontext,h262,keep_p); err = build_h262_filter_context_strip(&fcontext,h262,keep_p);
if (err) if (err)
{ {
fprintf(stderr,"### Unable to build filter context\n"); print_err("### Unable to build filter context\n");
free_h262_context(&h262); free_h262_context(&h262);
return 1; return 1;
} }
@ -206,12 +207,12 @@ static int strip_h262(ES_p es,
&seq_hdr,&picture,&delta_pictures_seen); &seq_hdr,&picture,&delta_pictures_seen);
if (err == EOF) if (err == EOF)
{ {
if (!quiet) printf("EOF\n"); if (!quiet) print_msg("EOF\n");
break; break;
} }
else if (err) else if (err)
{ {
fprintf(stderr,"### Error getting next stripped picture\n"); print_err("### Error getting next stripped picture\n");
free_h262_filter_context(&fcontext); free_h262_filter_context(&fcontext);
free_h262_context(&h262); free_h262_context(&h262);
return 1; return 1;
@ -225,7 +226,7 @@ static int strip_h262(ES_p es,
err = write_h262_picture(output,as_TS,seq_hdr); err = write_h262_picture(output,as_TS,seq_hdr);
if (err) if (err)
{ {
fprintf(stderr,"### Error writing picture\n"); print_err("### Error writing picture\n");
free_h262_picture(&picture); free_h262_picture(&picture);
free_h262_filter_context(&fcontext); free_h262_filter_context(&fcontext);
free_h262_context(&h262); free_h262_context(&h262);
@ -236,7 +237,7 @@ static int strip_h262(ES_p es,
err = write_h262_picture(output,as_TS,picture); err = write_h262_picture(output,as_TS,picture);
if (err) if (err)
{ {
fprintf(stderr,"### Error writing picture\n"); print_err("### Error writing picture\n");
free_h262_picture(&picture); free_h262_picture(&picture);
free_h262_filter_context(&fcontext); free_h262_filter_context(&fcontext);
free_h262_context(&h262); free_h262_context(&h262);
@ -247,7 +248,7 @@ static int strip_h262(ES_p es,
if (max > 0 && count >= max) if (max > 0 && count >= max)
{ {
if (!quiet) if (!quiet)
printf("Ending after %d pictures\n",count); fprint_msg("Ending after %d pictures\n",count);
break; break;
} }
} }
@ -257,9 +258,9 @@ static int strip_h262(ES_p es,
if (!quiet) if (!quiet)
{ {
printf("Found %d frames, kept %d (%.1f%%)\n", fprint_msg("Found %d frames, kept %d (%.1f%%)\n",
pictures_seen,pictures_kept, pictures_seen,pictures_kept,
100.0*pictures_kept/pictures_seen); 100.0*pictures_kept/pictures_seen);
} }
return 0; return 0;
} }
@ -310,14 +311,14 @@ static int filter_h262(ES_p es,
err = build_h262_context(es,&h262); err = build_h262_context(es,&h262);
if (err) if (err)
{ {
fprintf(stderr,"### Unable to build H.262 picture reading context\n"); print_err("### Unable to build H.262 picture reading context\n");
return 1; return 1;
} }
err = build_h262_filter_context(&fcontext,h262,frequency); err = build_h262_filter_context(&fcontext,h262,frequency);
if (err) if (err)
{ {
fprintf(stderr,"### Unable to build filter context\n"); print_err("### Unable to build filter context\n");
free_h262_context(&h262); free_h262_context(&h262);
return 1; return 1;
} }
@ -334,7 +335,7 @@ static int filter_h262(ES_p es,
} }
else if (err) else if (err)
{ {
fprintf(stderr,"### Error getting next filtered picture\n"); print_err("### Error getting next filtered picture\n");
free_h262_picture(&last_picture); free_h262_picture(&last_picture);
free_h262_filter_context(&fcontext); free_h262_filter_context(&fcontext);
free_h262_context(&h262); free_h262_context(&h262);
@ -357,7 +358,7 @@ static int filter_h262(ES_p es,
err = write_h262_picture(output,as_TS,seq_hdr); err = write_h262_picture(output,as_TS,seq_hdr);
if (err) if (err)
{ {
fprintf(stderr,"### Error writing sequence header\n"); print_err("### Error writing sequence header\n");
free_h262_picture(&this_picture); free_h262_picture(&this_picture);
free_h262_picture(&last_picture); free_h262_picture(&last_picture);
free_h262_filter_context(&fcontext); free_h262_filter_context(&fcontext);
@ -371,7 +372,7 @@ static int filter_h262(ES_p es,
err = write_h262_picture(output,as_TS,this_picture); err = write_h262_picture(output,as_TS,this_picture);
if (err) if (err)
{ {
fprintf(stderr,"### Error writing picture\n"); print_err("### Error writing picture\n");
free_h262_picture(&this_picture); free_h262_picture(&this_picture);
free_h262_picture(&last_picture); free_h262_picture(&last_picture);
free_h262_filter_context(&fcontext); free_h262_filter_context(&fcontext);
@ -387,7 +388,7 @@ static int filter_h262(ES_p es,
if (max > 0 && count >= max) if (max > 0 && count >= max)
{ {
if (!quiet) if (!quiet)
printf("Ending after %d frames\n",count); fprint_msg("Ending after %d frames\n",count);
free_h262_picture(&this_picture); free_h262_picture(&this_picture);
break; break;
} }
@ -398,19 +399,19 @@ static int filter_h262(ES_p es,
if (!quiet) if (!quiet)
{ {
printf("\n"); print_msg("\n");
printf("Summary\n"); print_msg("Summary\n");
printf("=======\n"); print_msg("=======\n");
printf(" Found Kept Written\n"); print_msg(" Found Kept Written\n");
printf("Frames %10d %10d (%4.1f%%) %10d (%4.1f%%)\n", fprint_msg("Frames %10d %10d (%4.1f%%) %10d (%4.1f%%)\n",
pictures_seen,pictures_kept, pictures_seen,pictures_kept,
100*(((double)pictures_kept)/pictures_seen), 100*(((double)pictures_kept)/pictures_seen),
pictures_written, pictures_written,
100*(((double)pictures_written)/pictures_seen)); 100*(((double)pictures_written)/pictures_seen));
if (frequency != 0) if (frequency != 0)
printf("Target (frames) . %10d (%4.1f%%) at requested" fprint_msg("Target (frames) . %10d (%4.1f%%) at requested"
" frequency %d\n",pictures_seen/frequency, " frequency %d\n",pictures_seen/frequency,
100.0/frequency,frequency); 100.0/frequency,frequency);
} }
return 0; return 0;
} }
@ -433,7 +434,7 @@ static int copy_nal_units(ES_p es,
err = build_nal_unit_context(es,&context); err = build_nal_unit_context(es,&context);
if (err) if (err)
{ {
fprintf(stderr,"### Unable to build NAL unit context to read ES\n"); print_err("### Unable to build NAL unit context to read ES\n");
return 1; return 1;
} }
@ -449,12 +450,12 @@ static int copy_nal_units(ES_p es,
break; break;
else if (err == 2) else if (err == 2)
{ {
fprintf(stderr,"!!! Ignoring broken NAL unit\n"); print_err("!!! Ignoring broken NAL unit\n");
continue; continue;
} }
else if (err) else if (err)
{ {
fprintf(stderr,"### Error getting next NAL unit\n"); print_err("### Error getting next NAL unit\n");
free_nal_unit_context(&context); free_nal_unit_context(&context);
return err; return err;
} }
@ -466,7 +467,7 @@ static int copy_nal_units(ES_p es,
if (err) if (err)
{ {
free_nal_unit(&nal); free_nal_unit(&nal);
fprintf(stderr,"### Error copying NAL units\n"); print_err("### Error copying NAL units\n");
free_nal_unit_context(&context); free_nal_unit_context(&context);
return err; return err;
} }
@ -474,8 +475,8 @@ static int copy_nal_units(ES_p es,
free_nal_unit(&nal); free_nal_unit(&nal);
} }
if (!quiet) if (!quiet)
printf("Processed %d NAL unit%s\n", fprint_msg("Processed %d NAL unit%s\n",
context->count,(context->count==1?"":"s")); context->count,(context->count==1?"":"s"));
free_nal_unit_context(&context); free_nal_unit_context(&context);
return 0; return 0;
} }
@ -508,13 +509,13 @@ static int strip_access_units(ES_p es,
err = build_access_unit_context(es,&acontext); err = build_access_unit_context(es,&acontext);
if (err) if (err)
{ {
fprintf(stderr,"### Unable to build access unit context\n"); print_err("### Unable to build access unit context\n");
return 1; return 1;
} }
err = build_h264_filter_context_strip(&fcontext,acontext,keep_all_ref); err = build_h264_filter_context_strip(&fcontext,acontext,keep_all_ref);
if (err) if (err)
{ {
fprintf(stderr,"### Unable to build filter context\n"); print_err("### Unable to build filter context\n");
free_access_unit_context(&acontext); free_access_unit_context(&acontext);
return 1; return 1;
} }
@ -530,7 +531,7 @@ static int strip_access_units(ES_p es,
break; break;
else if (err) else if (err)
{ {
fprintf(stderr,"### Error getting next stripped picture\n"); print_err("### Error getting next stripped picture\n");
free_h264_filter_context(&fcontext); free_h264_filter_context(&fcontext);
free_access_unit_context(&acontext); free_access_unit_context(&acontext);
return 1; return 1;
@ -547,7 +548,7 @@ static int strip_access_units(ES_p es,
output.es_output); output.es_output);
if (err) if (err)
{ {
fprintf(stderr,"### Error writing picture\n"); print_err("### Error writing picture\n");
free_h264_filter_context(&fcontext); free_h264_filter_context(&fcontext);
free_access_unit_context(&acontext); free_access_unit_context(&acontext);
return 1; return 1;
@ -557,7 +558,7 @@ static int strip_access_units(ES_p es,
if (max > 0 && count >= max) if (max > 0 && count >= max)
{ {
if (!quiet) if (!quiet)
printf("Ending after %d frames\n",count); fprint_msg("Ending after %d frames\n",count);
break; break;
} }
} }
@ -567,14 +568,14 @@ static int strip_access_units(ES_p es,
if (!quiet) if (!quiet)
{ {
printf("\n"); print_msg("\n");
printf("Summary\n"); print_msg("Summary\n");
printf("=======\n"); print_msg("=======\n");
printf(" Found Written\n"); print_msg(" Found Written\n");
printf("Access units %10d %10d (%4.1f%%)\n", fprint_msg("Access units %10d %10d (%4.1f%%)\n",
access_units_seen, access_units_seen,
access_units_kept, access_units_kept,
100*(((double)access_units_kept)/access_units_seen)); 100*(((double)access_units_kept)/access_units_seen));
} }
return 0; return 0;
} }
@ -608,13 +609,13 @@ static int filter_access_units(ES_p es,
err = build_access_unit_context(es,&acontext); err = build_access_unit_context(es,&acontext);
if (err) if (err)
{ {
fprintf(stderr,"### Unable to build access unit context\n"); print_err("### Unable to build access unit context\n");
return 1; return 1;
} }
err = build_h264_filter_context(&fcontext,acontext,frequency); err = build_h264_filter_context(&fcontext,acontext,frequency);
if (err) if (err)
{ {
fprintf(stderr,"### Unable to build filter context\n"); print_err("### Unable to build filter context\n");
free_access_unit_context(&acontext); free_access_unit_context(&acontext);
return 1; return 1;
} }
@ -629,7 +630,7 @@ static int filter_access_units(ES_p es,
break; break;
else if (err) else if (err)
{ {
fprintf(stderr,"### Error getting next filtered picture\n"); print_err("### Error getting next filtered picture\n");
free_access_unit(&last_access_unit); free_access_unit(&last_access_unit);
free_h264_filter_context(&fcontext); free_h264_filter_context(&fcontext);
free_access_unit_context(&acontext); free_access_unit_context(&acontext);
@ -659,7 +660,7 @@ static int filter_access_units(ES_p es,
output.es_output); output.es_output);
if (err) if (err)
{ {
fprintf(stderr,"### Error writing picture\n"); print_err("### Error writing picture\n");
free_access_unit(&this_access_unit); free_access_unit(&this_access_unit);
free_access_unit(&last_access_unit); free_access_unit(&last_access_unit);
free_h264_filter_context(&fcontext); free_h264_filter_context(&fcontext);
@ -675,7 +676,7 @@ static int filter_access_units(ES_p es,
if (max > 0 && count >= max) if (max > 0 && count >= max)
{ {
if (!quiet) if (!quiet)
printf("Ending after %d frames\n",count); fprint_msg("Ending after %d frames\n",count);
free_access_unit(&this_access_unit); free_access_unit(&this_access_unit);
break; break;
} }
@ -686,20 +687,20 @@ static int filter_access_units(ES_p es,
if (!quiet) if (!quiet)
{ {
printf("\n"); print_msg("\n");
printf("Summary\n"); print_msg("Summary\n");
printf("=======\n"); print_msg("=======\n");
printf(" Found Kept Written\n"); print_msg(" Found Kept Written\n");
printf("Frames %10d %10d (%4.1f%%) %10d (%4.1f%%)\n", fprint_msg("Frames %10d %10d (%4.1f%%) %10d (%4.1f%%)\n",
access_units_seen, access_units_seen,
access_units_kept, access_units_kept,
100*(((double)access_units_kept)/access_units_seen), 100*(((double)access_units_kept)/access_units_seen),
access_units_written, access_units_written,
100*(((double)access_units_written)/access_units_seen)); 100*(((double)access_units_written)/access_units_seen));
if (frequency != 0) if (frequency != 0)
printf("Target (frames) . %10d (%4.1f%%) at requested" fprint_msg("Target (frames) . %10d (%4.1f%%) at requested"
" frequency %d\n",access_units_seen/frequency, " frequency %d\n",access_units_seen/frequency,
100.0/frequency,frequency); 100.0/frequency,frequency);
} }
return 0; return 0;
} }
@ -728,9 +729,9 @@ static int do_action(ACTION action,
if (as_TS) if (as_TS)
{ {
if (!quiet) if (!quiet)
printf("Using transport stream id 1, PMT PID %#x, program 1 =" fprint_msg("Using transport stream id 1, PMT PID %#x, program 1 ="
" PID %#x, stream type %#x\n",DEFAULT_PMT_PID,DEFAULT_VIDEO_PID, " PID %#x, stream type %#x\n",DEFAULT_PMT_PID,DEFAULT_VIDEO_PID,
stream_type); stream_type);
err = write_TS_program_data(output.ts_output,1,1, err = write_TS_program_data(output.ts_output,1,1,
DEFAULT_PMT_PID,DEFAULT_VIDEO_PID,stream_type); DEFAULT_PMT_PID,DEFAULT_VIDEO_PID,stream_type);
if (err) return 1; if (err) return 1;
@ -760,7 +761,7 @@ static int do_action(ACTION action,
break; break;
default: default:
fprintf(stderr,"### Unexpected action %d\n",action); fprint_err("### Unexpected action %d\n",action);
err = 1; err = 1;
break; break;
} }
@ -769,12 +770,12 @@ static int do_action(ACTION action,
static void print_usage() static void print_usage()
{ {
printf( print_msg(
"Usage: esfilter [actions/switches] [<infile>] [<outfile>]\n" "Usage: esfilter [actions/switches] [<infile>] [<outfile>]\n"
"\n" "\n"
); );
REPORT_VERSION("esfilter"); REPORT_VERSION("esfilter");
printf( print_msg(
"\n" "\n"
" Output a filtered or truncated version of an elementary stream.\n" " Output a filtered or truncated version of an elementary stream.\n"
" The input is either H.264 (MPEG-4/AVC) or H.262 (MPEG-2).\n" " The input is either H.264 (MPEG-4/AVC) or H.262 (MPEG-2).\n"
@ -962,8 +963,8 @@ int main(int argc, char **argv)
} }
else else
{ {
fprintf(stderr,"### esfilter: " fprint_err("### esfilter: "
"Unrecognised command line switch '%s'\n",argv[ii]); "Unrecognised command line switch '%s'\n",argv[ii]);
return 1; return 1;
} }
} }
@ -971,7 +972,7 @@ int main(int argc, char **argv)
{ {
if (had_input_name && had_output_name) if (had_input_name && had_output_name)
{ {
fprintf(stderr,"### esfilter: Unexpected '%s'\n",argv[ii]); fprint_err("### esfilter: Unexpected '%s'\n",argv[ii]);
return 1; return 1;
} }
else if (had_input_name) else if (had_input_name)
@ -990,18 +991,18 @@ int main(int argc, char **argv)
if (!had_input_name) if (!had_input_name)
{ {
fprintf(stderr,"### esfilter: No input file specified\n"); print_err("### esfilter: No input file specified\n");
return 1; return 1;
} }
if (!had_output_name) if (!had_output_name)
{ {
fprintf(stderr,"### esfilter: No output file specified\n"); print_err("### esfilter: No output file specified\n");
return 1; return 1;
} }
if (action == ACTION_UNDEFINED) if (action == ACTION_UNDEFINED)
{ {
fprintf(stderr,"### esfilter: No action specified (-copy, -strip," print_err("### esfilter: No action specified (-copy, -strip,"
" -filter)\n"); " -filter)\n");
return 1; return 1;
} }
@ -1016,7 +1017,7 @@ int main(int argc, char **argv)
force_stream_type,want_data,&is_data,&es); force_stream_type,want_data,&is_data,&es);
if (err) if (err)
{ {
fprintf(stderr,"### esfilter: Error opening input file\n"); print_err("### esfilter: Error opening input file\n");
return 1; return 1;
} }
@ -1032,7 +1033,7 @@ int main(int argc, char **argv)
stream_type = AVC_VIDEO_STREAM_TYPE; stream_type = AVC_VIDEO_STREAM_TYPE;
else else
{ {
fprintf(stderr,"### esfilter: Unexpected type of video data\n"); print_err("### esfilter: Unexpected type of video data\n");
return 1; return 1;
} }
@ -1046,7 +1047,7 @@ int main(int argc, char **argv)
err = tswrite_open(TS_W_FILE,output_name,NULL,0,quiet,&(output.ts_output)); err = tswrite_open(TS_W_FILE,output_name,NULL,0,quiet,&(output.ts_output));
if (err) if (err)
{ {
fprintf(stderr,"### esfilter: Unable to open %s\n",output_name); fprint_err("### esfilter: Unable to open %s\n",output_name);
(void) close_input_as_ES(input_name,&es); (void) close_input_as_ES(input_name,&es);
return 1; return 1;
} }
@ -1056,47 +1057,47 @@ int main(int argc, char **argv)
output.es_output = fopen(output_name,"wb"); output.es_output = fopen(output_name,"wb");
if (output.es_output == NULL) if (output.es_output == NULL)
{ {
fprintf(stderr,"### esfilter: Unable to open output file %s: %s\n", fprint_err("### esfilter: Unable to open output file %s: %s\n",
output_name,strerror(errno)); output_name,strerror(errno));
(void) close_input_as_ES(input_name,&es); (void) close_input_as_ES(input_name,&es);
return 1; return 1;
} }
if (!quiet) if (!quiet)
printf("Writing to %s\n",output_name); fprint_msg("Writing to %s\n",output_name);
} }
if (!quiet) if (!quiet)
{ {
if (as_TS) if (as_TS)
printf("Writing as Transport Stream\n"); print_msg("Writing as Transport Stream\n");
if (action == ACTION_FILTER) if (action == ACTION_FILTER)
printf("Filtering freqency %d\n",frequency); fprint_msg("Filtering freqency %d\n",frequency);
if (action == ACTION_STRIP) if (action == ACTION_STRIP)
{ {
if (want_data == VIDEO_H262) if (want_data == VIDEO_H262)
{ {
if (keep_all_ref) if (keep_all_ref)
printf("Just keeping I and P pictures\n"); print_msg("Just keeping I and P pictures\n");
else else
printf("Just keep I pictures\n"); print_msg("Just keep I pictures\n");
} }
else else
{ {
if (keep_all_ref) if (keep_all_ref)
printf("Just keeping reference pictures\n"); print_msg("Just keeping reference pictures\n");
else else
printf("Just keep IDR and I pictures\n"); print_msg("Just keep IDR and I pictures\n");
} }
} }
if (max) if (max)
printf("Stopping as soon after %d NAL units as possible\n",max); fprint_msg("Stopping as soon after %d NAL units as possible\n",max);
} }
err = do_action(action,es,output,max,frequency,want_data==VIDEO_H262, err = do_action(action,es,output,max,frequency,want_data==VIDEO_H262,
as_TS,keep_all_ref,stream_type,verbose,quiet); as_TS,keep_all_ref,stream_type,verbose,quiet);
if (err) if (err)
{ {
fprintf(stderr,"### esfilter: Error doing '%s'\n",action_switch); fprint_err("### esfilter: Error doing '%s'\n",action_switch);
(void) close_input_as_ES(input_name,&es); (void) close_input_as_ES(input_name,&es);
if (as_TS) if (as_TS)
(void) tswrite_close(output.ts_output,TRUE); (void) tswrite_close(output.ts_output,TRUE);
@ -1104,9 +1105,8 @@ int main(int argc, char **argv)
{ {
err = fclose(output.es_output); err = fclose(output.es_output);
if (err) if (err)
fprintf(stderr, fprint_err("### esfilter: (Error closing output file %s: %s)\n",
"### esfilter: (Error closing output file %s: %s)\n", output_name,strerror(errno));
output_name,strerror(errno));
} }
return 1; return 1;
} }
@ -1117,7 +1117,7 @@ int main(int argc, char **argv)
err = tswrite_close(output.ts_output,quiet); err = tswrite_close(output.ts_output,quiet);
if (err) if (err)
{ {
fprintf(stderr,"### esfilter: Error closing output file %s",output_name); fprint_err("### esfilter: Error closing output file %s",output_name);
(void) close_input_as_ES(input_name,&es); (void) close_input_as_ES(input_name,&es);
return 1; return 1;
} }
@ -1128,8 +1128,8 @@ int main(int argc, char **argv)
err = fclose(output.es_output); err = fclose(output.es_output);
if (err) if (err)
{ {
fprintf(stderr,"### esfilter: Error closing output file %s: %s\n", fprint_err("### esfilter: Error closing output file %s: %s\n",
output_name,strerror(errno)); output_name,strerror(errno));
(void) close_input_as_ES(input_name,&es); (void) close_input_as_ES(input_name,&es);
return 1; return 1;
} }
@ -1138,7 +1138,7 @@ int main(int argc, char **argv)
err = close_input_as_ES(input_name,&es); err = close_input_as_ES(input_name,&es);
if (err) if (err)
{ {
fprintf(stderr,"### esfilter: Error closing input file\n"); print_err("### esfilter: Error closing input file\n");
return 1; return 1;
} }
return 0; return 0;