[Ffmpeg-devel] [PATCH] split av_encode function and do related reorder
Limin Wang
lance.lmwang
Mon Feb 26 12:55:09 CET 2007
Hi,
The attached patch try to cleanup ffmpeg.c av_encode function, I have pass
"make test" test. Please have review and give your comments. I don't know
whether ffmpeg developer like big function?
I feel it has too many lines code and too difficult to maintain and develop.
So I split it into three functions:
av_transcode_init(): ffmpeg transcode initialization
av_transcode_start(): main loop of file transcode
av_transcode_close(): ffmpeg transcode close, including resource/mem release,
the memory release order is first allocate(in av_transcode_init), last release.
If the patch is OK, I'll split av_transcode_init() into more functions for it's
too big still.
Thanks,
Limin
-------------- next part --------------
Index: ffmpeg.c
===================================================================
--- ffmpeg.c (revision 8129)
+++ ffmpeg.c (working copy)
@@ -277,6 +277,14 @@
int nb_streams; /* nb streams we are aware of */
} AVInputFile;
+typedef struct AVTranscodeContext {
+ AVOutputStream **ost_table;
+ AVInputStream **ist_table;
+ AVInputFile *file_table;
+ int nb_istreams;
+ int nb_ostreams;
+} AVTranscodeContext;
+
#ifndef __MINGW32__
/* init terminal so that we can grab keys */
@@ -1339,54 +1347,168 @@
return -1;
}
+/*
+ * The following code close the transcode context
+ */
+static int av_transcode_close( AVTranscodeContext *trans )
+{
+ int ret = 0;
+ int i;
+ AVOutputStream *ost;
+ AVInputStream *ist;
+ ByteIOContext *pb;
+ /* close each encoder */
+ for(i=0;i<trans->nb_ostreams;i++) {
+ ost = trans->ost_table[i];
+ if (ost && ost->encoding_needed) {
+ if( ost->st->codec->stats_in)
+ av_freep(&ost->st->codec->stats_in);
+ if( ost->st->codec )
+ avcodec_close(ost->st->codec);
+ }
+ }
+
+ /* close each decoder */
+ for(i=0;i<trans->nb_istreams;i++) {
+ ist = trans->ist_table[i];
+ if (ist && ist->decoding_needed) {
+ if( ist->st->codec )
+ avcodec_close(ist->st->codec);
+ }
+ }
+
+ if( bit_buffer )
+ av_freep(&bit_buffer);
+
+ if (trans->ost_table) {
+ for(i=0;i<trans->nb_ostreams;i++) {
+ ost = trans->ost_table[i];
+ if (ost) {
+ if (ost->logfile) {
+ fclose(ost->logfile);
+ ost->logfile = NULL;
+ }
+ av_fifo_free(&ost->fifo); /* works even if fifo is not
+ initialized but set to zero */
+ av_free(ost->pict_tmp.data[0]);
+ if (ost->video_resample)
+ sws_freeContext(ost->img_resample_ctx);
+ if (ost->audio_resample)
+ audio_resample_close(ost->resample);
+ av_free(ost);
+ }
+ }
+ av_free(trans->ost_table);
+ }
+
+ if (trans->ist_table) {
+ for(i=0;i<trans->nb_istreams;i++) {
+ ist = trans->ist_table[i];
+ if( ist )
+ av_free(ist);
+ }
+ av_free(trans->ist_table);
+ }
+
+ if( trans->file_table )
+ av_free(trans->file_table);
+
+ /* close output files which opened in opt_output_file */
+ for(i=0;i<nb_output_files;i++) {
+ /* maybe av_close_output_file ??? */
+ AVFormatContext *s = output_files[i];
+ int j;
+
+ pb = &s->pb;
+ if (!(s->oformat->flags & AVFMT_NOFILE) && pb )
+ url_fclose(pb);
+ for(j=0;j<s->nb_streams;j++) {
+ if( s->streams[j]->codec )
+ av_free(s->streams[j]->codec);
+ if( s->streams[j])
+ av_free(s->streams[j]);
+ }
+ av_free(s);
+ }
+
+ /* close input files which opened in opt_input_file */
+ for(i=0;i<nb_input_files;i++)
+ av_close_input_file(input_files[i]);
+
+ /* free memory which allocated in opt_intra_matrix */
+ if(intra_matrix)
+ av_free(intra_matrix);
+
+ /* free memory which allocated in opt_inter_matrix */
+ if(inter_matrix)
+ av_free(inter_matrix);
+
+ av_free_static();
+
+#ifdef CONFIG_POWERPC_PERF
+ extern void powerpc_display_perf_report(void);
+ powerpc_display_perf_report();
+#endif /* CONFIG_POWERPC_PERF */
+
+ if (received_sigterm) {
+ fprintf(stderr,
+ "Received signal %d: terminating.\n",
+ (int) received_sigterm);
+ exit (255);
+ }
+
+ return ret;
+}
+
/*
- * The following code is the main loop of the file converter
+ * The following code init the transcode context
*/
-static int av_encode(AVFormatContext **output_files,
- int nb_output_files,
- AVFormatContext **input_files,
- int nb_input_files,
- AVStreamMap *stream_maps, int nb_stream_maps)
+static int av_transcode_init( AVTranscodeContext *trans )
{
- int ret, i, j, k, n, nb_istreams = 0, nb_ostreams = 0;
- AVFormatContext *is, *os;
- AVCodecContext *codec, *icodec;
- AVOutputStream *ost, **ost_table = NULL;
- AVInputStream *ist, **ist_table = NULL;
- AVInputFile *file_table;
- AVFormatContext *stream_no_data;
- int key;
+ int ret=0, i, j, k, n;
+ AVOutputStream *ost;
+ AVInputStream *ist;
+ AVFormatContext *is;
+ AVFormatContext *os;
+ AVCodecContext *codec;
+ AVCodecContext *icodec;
- file_table= (AVInputFile*) av_mallocz(nb_input_files * sizeof(AVInputFile));
- if (!file_table)
- goto fail;
+ if( !trans ) {
+ ret = AVERROR(EINVAL);
+ goto fail1;
+ }
+ memset( trans, 0, sizeof(AVTranscodeContext) );
+ trans->file_table= (AVInputFile*) av_mallocz(nb_input_files * sizeof(AVInputFile));
+ if (!trans->file_table)
+ goto fail_nomem;
+
/* input stream init */
j = 0;
for(i=0;i<nb_input_files;i++) {
is = input_files[i];
- file_table[i].ist_index = j;
- file_table[i].nb_streams = is->nb_streams;
+ trans->file_table[i].ist_index = j;
+ trans->file_table[i].nb_streams = is->nb_streams;
j += is->nb_streams;
}
- nb_istreams = j;
+ trans->nb_istreams = j;
- ist_table = av_mallocz(nb_istreams * sizeof(AVInputStream *));
- if (!ist_table)
- goto fail;
+ trans->ist_table = av_mallocz(trans->nb_istreams * sizeof(AVInputStream *));
+ if (!trans->ist_table)
+ goto fail_nomem;
- for(i=0;i<nb_istreams;i++) {
+ for(i=0;i<trans->nb_istreams;i++) {
ist = av_mallocz(sizeof(AVInputStream));
if (!ist)
- goto fail;
- ist_table[i] = ist;
+ goto fail_nomem;
+ trans->ist_table[i] = ist;
}
j = 0;
for(i=0;i<nb_input_files;i++) {
is = input_files[i];
for(k=0;k<is->nb_streams;k++) {
- ist = ist_table[j++];
+ ist = trans->ist_table[j++];
ist->st = is->streams[k];
ist->file_index = i;
ist->index = k;
@@ -1401,16 +1523,16 @@
}
/* output stream init */
- nb_ostreams = 0;
+ trans->nb_ostreams = 0;
for(i=0;i<nb_output_files;i++) {
os = output_files[i];
if (!os->nb_streams) {
fprintf(stderr, "Output file does not contain any stream\n");
exit(1);
}
- nb_ostreams += os->nb_streams;
+ trans->nb_ostreams += os->nb_streams;
}
- if (nb_stream_maps > 0 && nb_stream_maps != nb_ostreams) {
+ if (nb_stream_maps > 0 && nb_stream_maps != trans->nb_ostreams) {
fprintf(stderr, "Number of stream maps must match number of output streams\n");
exit(1);
}
@@ -1421,27 +1543,27 @@
int si = stream_maps[i].stream_index;
if (fi < 0 || fi > nb_input_files - 1 ||
- si < 0 || si > file_table[fi].nb_streams - 1) {
+ si < 0 || si > trans->file_table[fi].nb_streams - 1) {
fprintf(stderr,"Could not find input stream #%d.%d\n", fi, si);
exit(1);
}
fi = stream_maps[i].sync_file_index;
si = stream_maps[i].sync_stream_index;
if (fi < 0 || fi > nb_input_files - 1 ||
- si < 0 || si > file_table[fi].nb_streams - 1) {
+ si < 0 || si > trans->file_table[fi].nb_streams - 1) {
fprintf(stderr,"Could not find sync stream #%d.%d\n", fi, si);
exit(1);
}
}
- ost_table = av_mallocz(sizeof(AVOutputStream *) * nb_ostreams);
- if (!ost_table)
- goto fail;
- for(i=0;i<nb_ostreams;i++) {
+ trans->ost_table = av_mallocz(sizeof(AVOutputStream *) * trans->nb_ostreams);
+ if (!trans->ost_table)
+ goto fail_nomem;
+ for(i=0;i<trans->nb_ostreams;i++) {
ost = av_mallocz(sizeof(AVOutputStream));
if (!ost)
- goto fail;
- ost_table[i] = ost;
+ goto fail_nomem;
+ trans->ost_table[i] = ost;
}
n = 0;
@@ -1449,16 +1571,17 @@
os = output_files[k];
for(i=0;i<os->nb_streams;i++) {
int found;
- ost = ost_table[n++];
+ ost = trans->ost_table[n++];
ost->file_index = k;
ost->index = i;
ost->st = os->streams[i];
if (nb_stream_maps > 0) {
- ost->source_index = file_table[stream_maps[n-1].file_index].ist_index +
+ ost->source_index = trans->file_table[stream_maps[n-1].file_index].ist_index +
stream_maps[n-1].stream_index;
/* Sanity check that the stream types match */
- if (ist_table[ost->source_index]->st->codec->codec_type != ost->st->codec->codec_type) {
+ if (trans->ist_table[ost->source_index]->st->codec->codec_type
+ != ost->st->codec->codec_type) {
fprintf(stderr, "Codec type mismatch for mapping #%d.%d -> #%d.%d\n",
stream_maps[n-1].file_index, stream_maps[n-1].stream_index,
ost->file_index, ost->index);
@@ -1468,8 +1591,8 @@
} else {
/* get corresponding input stream index : we select the first one with the right type */
found = 0;
- for(j=0;j<nb_istreams;j++) {
- ist = ist_table[j];
+ for(j=0;j<trans->nb_istreams;j++) {
+ ist = trans->ist_table[j];
if (ist->discard &&
ist->st->codec->codec_type == ost->st->codec->codec_type) {
ost->source_index = j;
@@ -1480,8 +1603,8 @@
if (!found) {
/* try again and reuse existing stream */
- for(j=0;j<nb_istreams;j++) {
- ist = ist_table[j];
+ for(j=0;j<trans->nb_istreams;j++) {
+ ist = trans->ist_table[j];
if (ist->st->codec->codec_type == ost->st->codec->codec_type) {
ost->source_index = j;
found = 1;
@@ -1494,18 +1617,18 @@
}
}
}
- ist = ist_table[ost->source_index];
+ ist = trans->ist_table[ost->source_index];
ist->discard = 0;
ost->sync_ist = (nb_stream_maps > 0) ?
- ist_table[file_table[stream_maps[n-1].sync_file_index].ist_index +
+ trans->ist_table[trans->file_table[stream_maps[n-1].sync_file_index].ist_index +
stream_maps[n-1].sync_stream_index] : ist;
}
}
/* for each output stream, we compute the right encoding parameters */
- for(i=0;i<nb_ostreams;i++) {
- ost = ost_table[i];
- ist = ist_table[ost->source_index];
+ for(i=0;i<trans->nb_ostreams;i++) {
+ ost = trans->ost_table[i];
+ ist = trans->ist_table[ost->source_index];
codec = ost->st->codec;
icodec = ist->st->codec;
@@ -1548,7 +1671,7 @@
switch(codec->codec_type) {
case CODEC_TYPE_AUDIO:
if (av_fifo_init(&ost->fifo, 2 * MAX_AUDIO_PACKET_SIZE))
- goto fail;
+ goto fail_nomem;
if (codec->channels == icodec->channels &&
codec->sample_rate == icodec->sample_rate) {
@@ -1607,14 +1730,14 @@
avcodec_get_frame_defaults(&ost->pict_tmp);
if( avpicture_alloc( (AVPicture*)&ost->pict_tmp, codec->pix_fmt,
codec->width, codec->height ) )
- goto fail;
+ goto fail_nomem;
}
}
if (ost->video_resample) {
avcodec_get_frame_defaults(&ost->pict_tmp);
if( avpicture_alloc( (AVPicture*)&ost->pict_tmp, codec->pix_fmt,
codec->width, codec->height ) )
- goto fail;
+ goto fail_nomem;
ost->img_resample_ctx = sws_getContext(
icodec->width - (frame_leftBand + frame_rightBand),
@@ -1690,7 +1813,7 @@
if (!bit_buffer)
bit_buffer = av_malloc(bit_buffer_size);
if (!bit_buffer)
- goto fail;
+ goto fail_nomem;
/* dump the file output parameters - cannot be done before in case
of stream copy */
@@ -1701,14 +1824,14 @@
/* dump the stream mapping */
if (verbose >= 0) {
fprintf(stderr, "Stream mapping:\n");
- for(i=0;i<nb_ostreams;i++) {
- ost = ost_table[i];
+ for(i=0;i<trans->nb_ostreams;i++) {
+ ost = trans->ost_table[i];
fprintf(stderr, " Stream #%d.%d -> #%d.%d",
- ist_table[ost->source_index]->file_index,
- ist_table[ost->source_index]->index,
+ trans->ist_table[ost->source_index]->file_index,
+ trans->ist_table[ost->source_index]->index,
ost->file_index,
ost->index);
- if (ost->sync_ist != ist_table[ost->source_index])
+ if (ost->sync_ist != trans->ist_table[ost->source_index])
fprintf(stderr, " [sync #%d.%d]",
ost->sync_ist->file_index,
ost->sync_ist->index);
@@ -1717,8 +1840,8 @@
}
/* open each encoder */
- for(i=0;i<nb_ostreams;i++) {
- ost = ost_table[i];
+ for(i=0;i<trans->nb_ostreams;i++) {
+ ost = trans->ost_table[i];
if (ost->encoding_needed) {
AVCodec *codec;
codec = avcodec_find_encoder(ost->st->codec->codec_id);
@@ -1728,7 +1851,8 @@
exit(1);
}
if (avcodec_open(ost->st->codec, codec) < 0) {
- fprintf(stderr, "Error while opening codec for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height\n",
+ fprintf(stderr, "Error while opening codec for output stream #%d.%d "
+ "- maybe incorrect parameters such as bit_rate, rate, width or height\n",
ost->file_index, ost->index);
exit(1);
}
@@ -1737,8 +1861,8 @@
}
/* open each decoder */
- for(i=0;i<nb_istreams;i++) {
- ist = ist_table[i];
+ for(i=0;i<trans->nb_istreams;i++) {
+ ist = trans->ist_table[i];
if (ist->decoding_needed) {
AVCodec *codec;
codec = avcodec_find_decoder(ist->st->codec->codec_id);
@@ -1758,8 +1882,8 @@
}
/* init pts */
- for(i=0;i<nb_istreams;i++) {
- ist = ist_table[i];
+ for(i=0;i<trans->nb_istreams;i++) {
+ ist = trans->ist_table[i];
is = input_files[ist->file_index];
ist->pts = 0;
ist->next_pts = av_rescale_q(ist->st->start_time, ist->st->time_base, AV_TIME_BASE_Q);
@@ -1772,7 +1896,7 @@
/* compute buffer size max (should use a complete heuristic) */
for(i=0;i<nb_input_files;i++) {
- file_table[i].buffer_size_max = 2048;
+ trans->file_table[i].buffer_size_max = 2048;
}
/* set meta data information from input file if required */
@@ -1783,14 +1907,14 @@
int out_file_index = meta_data_maps[i].out_file;
int in_file_index = meta_data_maps[i].in_file;
if ( out_file_index < 0 || out_file_index >= nb_output_files ) {
- fprintf(stderr, "Invalid output file index %d map_meta_data(%d,%d)\n", out_file_index, out_file_index, in_file_index);
- ret = AVERROR(EINVAL);
- goto fail;
+ fprintf(stderr, "Invalid output file index %d map_meta_data(%d,%d)\n",
+ out_file_index, out_file_index, in_file_index);
+ exit(1);
}
if ( in_file_index < 0 || in_file_index >= nb_input_files ) {
- fprintf(stderr, "Invalid input file index %d map_meta_data(%d,%d)\n", in_file_index, out_file_index, in_file_index);
- ret = AVERROR(EINVAL);
- goto fail;
+ fprintf(stderr, "Invalid input file index %d map_meta_data(%d,%d)\n",
+ in_file_index, out_file_index, in_file_index);
+ exit(1);
}
out_file = output_files[out_file_index];
@@ -1811,8 +1935,7 @@
os = output_files[i];
if (av_write_header(os) < 0) {
fprintf(stderr, "Could not write header for output file #%d (incorrect codec parameters ?)\n", i);
- ret = AVERROR(EINVAL);
- goto fail;
+ exit(1);
}
}
@@ -1820,6 +1943,32 @@
fprintf(stderr, "Press [q] to stop encoding\n");
url_set_interrupt_cb(decode_interrupt_cb);
}
+
+done:
+ return ret;
+
+fail1:
+ av_transcode_close( trans );
+ goto done;
+
+fail_nomem:
+ ret = AVERROR(ret);
+ goto fail1;
+}
+
+/*
+ * The following code is the main loop of the file converter
+ */
+static int av_transcode_start( AVTranscodeContext *trans )
+{
+ int i;
+ AVFormatContext *stream_no_data;
+ AVOutputStream *ost;
+ AVInputStream *ist;
+ AVFormatContext *is;
+ AVFormatContext *os;
+ int key;
+
term_init();
stream_no_data = 0;
@@ -1847,17 +1996,17 @@
/* select the stream that we must read now by looking at the
smallest output pts */
file_index = -1;
- for(i=0;i<nb_ostreams;i++) {
+ for(i=0;i<trans->nb_ostreams;i++) {
double ipts, opts;
- ost = ost_table[i];
+ ost = trans->ost_table[i];
os = output_files[ost->file_index];
- ist = ist_table[ost->source_index];
+ ist = trans->ist_table[ost->source_index];
if(ost->st->codec->codec_type == CODEC_TYPE_VIDEO)
opts = ost->sync_opts * av_q2d(ost->st->codec->time_base);
else
opts = ost->st->pts.val * av_q2d(ost->st->time_base);
ipts = (double)ist->pts;
- if (!file_table[ist->file_index].eof_reached){
+ if (!trans->file_table[ist->file_index].eof_reached){
if(ipts < ipts_min) {
ipts_min = ipts;
if(input_sync ) file_index = ist->file_index;
@@ -1888,7 +2037,7 @@
/* read a frame from it and output it in the fifo */
is = input_files[file_index];
if (av_read_frame(is, &pkt) < 0) {
- file_table[file_index].eof_reached = 1;
+ trans->file_table[file_index].eof_reached = 1;
if (opt_shortest) break; else continue; //
}
@@ -1902,10 +2051,10 @@
}
/* the following test is needed in case new streams appear
dynamically in stream : we ignore them */
- if (pkt.stream_index >= file_table[file_index].nb_streams)
+ if (pkt.stream_index >= trans->file_table[file_index].nb_streams)
goto discard_packet;
- ist_index = file_table[file_index].ist_index + pkt.stream_index;
- ist = ist_table[ist_index];
+ ist_index = trans->file_table[file_index].ist_index + pkt.stream_index;
+ ist = trans->ist_table[ist_index];
if (ist->discard)
goto discard_packet;
@@ -1915,17 +2064,18 @@
if(FFABS(delta) > 1LL*dts_delta_threshold*AV_TIME_BASE && !copy_ts){
input_files_ts_offset[ist->file_index]-= delta;
if (verbose > 2)
- fprintf(stderr, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n", delta, input_files_ts_offset[ist->file_index]);
- for(i=0; i<file_table[file_index].nb_streams; i++){
- int index= file_table[file_index].ist_index + i;
- ist_table[index]->next_pts += delta;
- ist_table[index]->is_start=1;
+ fprintf(stderr, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
+ delta, input_files_ts_offset[ist->file_index]);
+ for(i=0; i<trans->file_table[file_index].nb_streams; i++){
+ int index= trans->file_table[file_index].ist_index + i;
+ trans->ist_table[index]->next_pts += delta;
+ trans->ist_table[index]->is_start=1;
}
}
}
//fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->index, pkt.size);
- if (output_packet(ist, ist_index, ost_table, nb_ostreams, &pkt) < 0) {
+ if (output_packet(ist, ist_index, trans->ost_table, trans->nb_ostreams, &pkt) < 0) {
if (verbose >= 0)
fprintf(stderr, "Error while decoding stream #%d.%d\n",
@@ -1939,14 +2089,14 @@
av_free_packet(&pkt);
/* dump report by using the output first video and audio streams */
- print_report(output_files, ost_table, nb_ostreams, 0);
+ print_report(output_files, trans->ost_table, trans->nb_ostreams, 0);
}
/* at the end of stream, we must flush the decoder buffers */
- for(i=0;i<nb_istreams;i++) {
- ist = ist_table[i];
+ for(i=0;i<trans->nb_istreams;i++) {
+ ist = trans->ist_table[i];
if (ist->decoding_needed) {
- output_packet(ist, i, ost_table, nb_ostreams, NULL);
+ output_packet(ist, i, trans->ost_table, trans->nb_ostreams, NULL);
}
}
@@ -1959,63 +2109,9 @@
}
/* dump report by using the first video and audio streams */
- print_report(output_files, ost_table, nb_ostreams, 1);
+ print_report(output_files, trans->ost_table, trans->nb_ostreams, 1);
- /* close each encoder */
- for(i=0;i<nb_ostreams;i++) {
- ost = ost_table[i];
- if (ost->encoding_needed) {
- av_freep(&ost->st->codec->stats_in);
- avcodec_close(ost->st->codec);
- }
- }
-
- /* close each decoder */
- for(i=0;i<nb_istreams;i++) {
- ist = ist_table[i];
- if (ist->decoding_needed) {
- avcodec_close(ist->st->codec);
- }
- }
-
- /* finished ! */
-
- ret = 0;
- fail1:
- av_freep(&bit_buffer);
- av_free(file_table);
-
- if (ist_table) {
- for(i=0;i<nb_istreams;i++) {
- ist = ist_table[i];
- av_free(ist);
- }
- av_free(ist_table);
- }
- if (ost_table) {
- for(i=0;i<nb_ostreams;i++) {
- ost = ost_table[i];
- if (ost) {
- if (ost->logfile) {
- fclose(ost->logfile);
- ost->logfile = NULL;
- }
- av_fifo_free(&ost->fifo); /* works even if fifo is not
- initialized but set to zero */
- av_free(ost->pict_tmp.data[0]);
- if (ost->video_resample)
- sws_freeContext(ost->img_resample_ctx);
- if (ost->audio_resample)
- audio_resample_close(ost->resample);
- av_free(ost);
- }
- }
- av_free(ost_table);
- }
- return ret;
- fail:
- ret = AVERROR(ENOMEM);
- goto fail1;
+ return 0;
}
#if 0
@@ -2535,6 +2631,10 @@
/* get default parameters from command line */
ic = av_alloc_format_context();
+ if( !ic ) {
+ fprintf(stderr, "av_alloc_format_context failed\n" );
+ exit(1);
+ }
memset(ap, 0, sizeof(*ap));
ap->prealloced_context = 1;
@@ -3014,6 +3114,10 @@
filename = "pipe:";
oc = av_alloc_format_context();
+ if( !oc ) {
+ fprintf(stderr, "av_alloc_format_context failed\n" );
+ exit(1);
+ }
if (!file_oformat) {
file_oformat = guess_format(NULL, filename, NULL);
@@ -3763,8 +3867,9 @@
int main(int argc, char **argv)
{
- int i;
int64_t ti;
+ AVTranscodeContext trans;
+ int ret;
av_register_all();
@@ -3791,46 +3896,19 @@
}
ti = getutime();
- av_encode(output_files, nb_output_files, input_files, nb_input_files,
- stream_maps, nb_stream_maps);
- ti = getutime() - ti;
- if (do_benchmark) {
- printf("bench: utime=%0.3fs\n", ti / 1000000.0);
+ ret = av_transcode_init( &trans );
+ if( ret < 0 ) {
+ fprintf(stderr, "Transcode init failed\n");
+ exit(1);
}
- /* close files */
- for(i=0;i<nb_output_files;i++) {
- /* maybe av_close_output_file ??? */
- AVFormatContext *s = output_files[i];
- int j;
- if (!(s->oformat->flags & AVFMT_NOFILE))
- url_fclose(&s->pb);
- for(j=0;j<s->nb_streams;j++) {
- av_free(s->streams[j]->codec);
- av_free(s->streams[j]);
- }
- av_free(s);
- }
- for(i=0;i<nb_input_files;i++)
- av_close_input_file(input_files[i]);
+ av_transcode_start( &trans );
- av_free_static();
+ av_transcode_close( &trans );
- if(intra_matrix)
- av_free(intra_matrix);
- if(inter_matrix)
- av_free(inter_matrix);
-
-#ifdef CONFIG_POWERPC_PERF
- extern void powerpc_display_perf_report(void);
- powerpc_display_perf_report();
-#endif /* CONFIG_POWERPC_PERF */
-
- if (received_sigterm) {
- fprintf(stderr,
- "Received signal %d: terminating.\n",
- (int) received_sigterm);
- exit (255);
+ ti = getutime() - ti;
+ if (do_benchmark) {
+ printf("bench: utime=%0.3fs\n", ti / 1000000.0);
}
exit(0); /* not all OS-es handle main() return value */
More information about the ffmpeg-devel
mailing list