mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avconv: use different variables for decoded and filtered frame.
Makes the code less obfuscated and fixes encoding one video stream to several outputs. Also use avcodec_alloc_frame() instead of allocating AVFrame on stack. Breaks me_threshold in avconv, as motion vectors aren't passed through lavfi. They could be copied manually, but I don't think this misfeature is useful enough to justify ugly hacks.
This commit is contained in:
parent
3ccd15803b
commit
d3c1d37a90
36
avconv.c
36
avconv.c
@ -1520,7 +1520,6 @@ static int output_packet(InputStream *ist, int ist_index,
|
|||||||
OutputStream *ost;
|
OutputStream *ost;
|
||||||
int ret, i;
|
int ret, i;
|
||||||
int got_output;
|
int got_output;
|
||||||
AVFrame picture;
|
|
||||||
void *buffer_to_free = NULL;
|
void *buffer_to_free = NULL;
|
||||||
static unsigned int samples_size= 0;
|
static unsigned int samples_size= 0;
|
||||||
AVSubtitle subtitle, *subtitle_to_free;
|
AVSubtitle subtitle, *subtitle_to_free;
|
||||||
@ -1555,6 +1554,7 @@ static int output_packet(InputStream *ist, int ist_index,
|
|||||||
while (avpkt.size > 0 || (!pkt && got_output)) {
|
while (avpkt.size > 0 || (!pkt && got_output)) {
|
||||||
uint8_t *data_buf, *decoded_data_buf;
|
uint8_t *data_buf, *decoded_data_buf;
|
||||||
int data_size, decoded_data_size;
|
int data_size, decoded_data_size;
|
||||||
|
AVFrame *decoded_frame, *filtered_frame;
|
||||||
handle_eof:
|
handle_eof:
|
||||||
ist->pts= ist->next_pts;
|
ist->pts= ist->next_pts;
|
||||||
|
|
||||||
@ -1564,6 +1564,7 @@ static int output_packet(InputStream *ist, int ist_index,
|
|||||||
ist->showed_multi_packet_warning=1;
|
ist->showed_multi_packet_warning=1;
|
||||||
|
|
||||||
/* decode the packet if needed */
|
/* decode the packet if needed */
|
||||||
|
decoded_frame = filtered_frame = NULL;
|
||||||
decoded_data_buf = NULL; /* fail safe */
|
decoded_data_buf = NULL; /* fail safe */
|
||||||
decoded_data_size= 0;
|
decoded_data_size= 0;
|
||||||
data_buf = avpkt.data;
|
data_buf = avpkt.data;
|
||||||
@ -1600,22 +1601,24 @@ static int output_packet(InputStream *ist, int ist_index,
|
|||||||
break;}
|
break;}
|
||||||
case AVMEDIA_TYPE_VIDEO:
|
case AVMEDIA_TYPE_VIDEO:
|
||||||
decoded_data_size = (ist->st->codec->width * ist->st->codec->height * 3) / 2;
|
decoded_data_size = (ist->st->codec->width * ist->st->codec->height * 3) / 2;
|
||||||
/* XXX: allocate picture correctly */
|
if (!(decoded_frame = avcodec_alloc_frame()))
|
||||||
avcodec_get_frame_defaults(&picture);
|
return AVERROR(ENOMEM);
|
||||||
avpkt.pts = pkt_pts;
|
avpkt.pts = pkt_pts;
|
||||||
avpkt.dts = ist->pts;
|
avpkt.dts = ist->pts;
|
||||||
pkt_pts = AV_NOPTS_VALUE;
|
pkt_pts = AV_NOPTS_VALUE;
|
||||||
|
|
||||||
ret = avcodec_decode_video2(ist->st->codec,
|
ret = avcodec_decode_video2(ist->st->codec,
|
||||||
&picture, &got_output, &avpkt);
|
decoded_frame, &got_output, &avpkt);
|
||||||
quality = same_quant ? picture.quality : 0;
|
quality = same_quant ? decoded_frame->quality : 0;
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
goto fail;
|
||||||
if (!got_output) {
|
if (!got_output) {
|
||||||
/* no picture yet */
|
/* no picture yet */
|
||||||
|
av_freep(&decoded_frame);
|
||||||
goto discard_packet;
|
goto discard_packet;
|
||||||
}
|
}
|
||||||
ist->next_pts = ist->pts = guess_correct_pts(&ist->pts_ctx, picture.pkt_pts, picture.pkt_dts);
|
ist->next_pts = ist->pts = guess_correct_pts(&ist->pts_ctx, decoded_frame->pkt_pts,
|
||||||
|
decoded_frame->pkt_dts);
|
||||||
if (ist->st->codec->time_base.num != 0) {
|
if (ist->st->codec->time_base.num != 0) {
|
||||||
int ticks= ist->st->parser ? ist->st->parser->repeat_pict+1 : ist->st->codec->ticks_per_frame;
|
int ticks= ist->st->parser ? ist->st->parser->repeat_pict+1 : ist->st->codec->ticks_per_frame;
|
||||||
ist->next_pts += ((int64_t)AV_TIME_BASE *
|
ist->next_pts += ((int64_t)AV_TIME_BASE *
|
||||||
@ -1624,7 +1627,7 @@ static int output_packet(InputStream *ist, int ist_index,
|
|||||||
}
|
}
|
||||||
avpkt.size = 0;
|
avpkt.size = 0;
|
||||||
buffer_to_free = NULL;
|
buffer_to_free = NULL;
|
||||||
pre_process_video_frame(ist, (AVPicture *)&picture, &buffer_to_free);
|
pre_process_video_frame(ist, (AVPicture *)decoded_frame, &buffer_to_free);
|
||||||
break;
|
break;
|
||||||
case AVMEDIA_TYPE_SUBTITLE:
|
case AVMEDIA_TYPE_SUBTITLE:
|
||||||
ret = avcodec_decode_subtitle2(ist->st->codec,
|
ret = avcodec_decode_subtitle2(ist->st->codec,
|
||||||
@ -1705,16 +1708,22 @@ static int output_packet(InputStream *ist, int ist_index,
|
|||||||
sar = ist->st->sample_aspect_ratio;
|
sar = ist->st->sample_aspect_ratio;
|
||||||
else
|
else
|
||||||
sar = ist->st->codec->sample_aspect_ratio;
|
sar = ist->st->codec->sample_aspect_ratio;
|
||||||
av_vsrc_buffer_add_frame(ost->input_video_filter, &picture, ist->pts, sar);
|
av_vsrc_buffer_add_frame(ost->input_video_filter, decoded_frame, ist->pts, sar);
|
||||||
|
if (!(filtered_frame = avcodec_alloc_frame())) {
|
||||||
|
ret = AVERROR(ENOMEM);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
frame_available = ist->st->codec->codec_type != AVMEDIA_TYPE_VIDEO ||
|
frame_available = ist->st->codec->codec_type != AVMEDIA_TYPE_VIDEO ||
|
||||||
!ost->output_video_filter || avfilter_poll_frame(ost->output_video_filter->inputs[0]);
|
!ost->output_video_filter || avfilter_poll_frame(ost->output_video_filter->inputs[0]);
|
||||||
while (frame_available) {
|
while (frame_available) {
|
||||||
AVRational ist_pts_tb;
|
AVRational ist_pts_tb;
|
||||||
if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ost->output_video_filter)
|
if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ost->output_video_filter)
|
||||||
get_filtered_video_frame(ost->output_video_filter, &picture, &ost->picref, &ist_pts_tb);
|
get_filtered_video_frame(ost->output_video_filter, filtered_frame, &ost->picref, &ist_pts_tb);
|
||||||
if (ost->picref)
|
if (ost->picref)
|
||||||
ist->pts = av_rescale_q(ost->picref->pts, ist_pts_tb, AV_TIME_BASE_Q);
|
ist->pts = av_rescale_q(ost->picref->pts, ist_pts_tb, AV_TIME_BASE_Q);
|
||||||
|
#else
|
||||||
|
filtered_frame = decoded_frame;
|
||||||
#endif
|
#endif
|
||||||
os = output_files[ost->file_index].ctx;
|
os = output_files[ost->file_index].ctx;
|
||||||
|
|
||||||
@ -1732,7 +1741,7 @@ static int output_packet(InputStream *ist, int ist_index,
|
|||||||
if (ost->picref->video && !ost->frame_aspect_ratio)
|
if (ost->picref->video && !ost->frame_aspect_ratio)
|
||||||
ost->st->codec->sample_aspect_ratio = ost->picref->video->pixel_aspect;
|
ost->st->codec->sample_aspect_ratio = ost->picref->video->pixel_aspect;
|
||||||
#endif
|
#endif
|
||||||
do_video_out(os, ost, ist, &picture, &frame_size,
|
do_video_out(os, ost, ist, filtered_frame, &frame_size,
|
||||||
same_quant ? quality : ost->st->codec->global_quality);
|
same_quant ? quality : ost->st->codec->global_quality);
|
||||||
if (vstats_filename && frame_size)
|
if (vstats_filename && frame_size)
|
||||||
do_video_stats(os, ost, frame_size);
|
do_video_stats(os, ost, frame_size);
|
||||||
@ -1806,15 +1815,20 @@ static int output_packet(InputStream *ist, int ist_index,
|
|||||||
if (ost->picref)
|
if (ost->picref)
|
||||||
avfilter_unref_buffer(ost->picref);
|
avfilter_unref_buffer(ost->picref);
|
||||||
}
|
}
|
||||||
|
av_freep(&filtered_frame);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fail:
|
||||||
av_free(buffer_to_free);
|
av_free(buffer_to_free);
|
||||||
/* XXX: allocate the subtitles in the codec ? */
|
/* XXX: allocate the subtitles in the codec ? */
|
||||||
if (subtitle_to_free) {
|
if (subtitle_to_free) {
|
||||||
avsubtitle_free(subtitle_to_free);
|
avsubtitle_free(subtitle_to_free);
|
||||||
subtitle_to_free = NULL;
|
subtitle_to_free = NULL;
|
||||||
}
|
}
|
||||||
|
av_freep(&decoded_frame);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
discard_packet:
|
discard_packet:
|
||||||
|
|
||||||
|
@ -55,11 +55,6 @@ do_video_decoding
|
|||||||
# mpeg2 encoding interlaced using intra vlc
|
# mpeg2 encoding interlaced using intra vlc
|
||||||
do_video_encoding mpeg2threadivlc.mpg "-qscale 10 -vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -flags2 +ivlc -threads 2"
|
do_video_encoding mpeg2threadivlc.mpg "-qscale 10 -vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -flags2 +ivlc -threads 2"
|
||||||
do_video_decoding
|
do_video_decoding
|
||||||
|
|
||||||
# mpeg2 encoding interlaced
|
|
||||||
file=${outfile}mpeg2reuse.mpg
|
|
||||||
do_avconv $file $DEC_OPTS -me_threshold 256 -i ${target_path}/${outfile}mpeg2thread.mpg $ENC_OPTS -same_quant -me_threshold 256 -mb_threshold 1024 -vcodec mpeg2video -vsync 0 -f mpeg1video -bf 2 -flags +ildct+ilme -threads 4
|
|
||||||
do_video_decoding
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$do_msmpeg4v2" ] ; then
|
if [ -n "$do_msmpeg4v2" ] ; then
|
||||||
|
@ -6,7 +6,3 @@ stddev: 7.63 PSNR: 30.48 MAXDIFF: 110 bytes: 7603200/ 7603200
|
|||||||
791773 ./tests/data/vsynth1/mpeg2threadivlc.mpg
|
791773 ./tests/data/vsynth1/mpeg2threadivlc.mpg
|
||||||
d1658911ca83f5616c1d32abc40750de *./tests/data/mpeg2thread.vsynth1.out.yuv
|
d1658911ca83f5616c1d32abc40750de *./tests/data/mpeg2thread.vsynth1.out.yuv
|
||||||
stddev: 7.63 PSNR: 30.48 MAXDIFF: 110 bytes: 7603200/ 7603200
|
stddev: 7.63 PSNR: 30.48 MAXDIFF: 110 bytes: 7603200/ 7603200
|
||||||
d119fe917dd81d1ff758b4ce684a8d9d *./tests/data/vsynth1/mpeg2reuse.mpg
|
|
||||||
2074636 ./tests/data/vsynth1/mpeg2reuse.mpg
|
|
||||||
92ced6afe8c02304943c400cce51a5f4 *./tests/data/mpeg2thread.vsynth1.out.yuv
|
|
||||||
stddev: 7.66 PSNR: 30.44 MAXDIFF: 111 bytes: 7603200/ 7603200
|
|
||||||
|
@ -6,7 +6,3 @@ stddev: 4.72 PSNR: 34.65 MAXDIFF: 72 bytes: 7603200/ 7603200
|
|||||||
178801 ./tests/data/vsynth2/mpeg2threadivlc.mpg
|
178801 ./tests/data/vsynth2/mpeg2threadivlc.mpg
|
||||||
8c6a7ed2eb73bd18fd2bb9829464100d *./tests/data/mpeg2thread.vsynth2.out.yuv
|
8c6a7ed2eb73bd18fd2bb9829464100d *./tests/data/mpeg2thread.vsynth2.out.yuv
|
||||||
stddev: 4.72 PSNR: 34.65 MAXDIFF: 72 bytes: 7603200/ 7603200
|
stddev: 4.72 PSNR: 34.65 MAXDIFF: 72 bytes: 7603200/ 7603200
|
||||||
864d6bf2982a61e510003a518be65a2d *./tests/data/vsynth2/mpeg2reuse.mpg
|
|
||||||
383419 ./tests/data/vsynth2/mpeg2reuse.mpg
|
|
||||||
bb20fa080cfd2b0a687ea7376ff4f902 *./tests/data/mpeg2thread.vsynth2.out.yuv
|
|
||||||
stddev: 4.73 PSNR: 34.63 MAXDIFF: 72 bytes: 7603200/ 7603200
|
|
||||||
|
Loading…
Reference in New Issue
Block a user