summaryrefslogtreecommitdiff
path: root/ffmpeg.c
diff options
context:
space:
mode:
authorStefano Sabatini <stefano.sabatini-lala@poste.it>2011-05-02 09:35:38 +0200
committerStefano Sabatini <stefano.sabatini-lala@poste.it>2011-05-07 12:03:58 +0200
commitf5a669c229425cdac828c230addf10d6d9cbe3a7 (patch)
tree1b5316ff693492059237401d0b7013851e227dcf /ffmpeg.c
parent566666caf3a09d6254edaa99d222eddb6fe2986b (diff)
ffmpeg: simplify mid-stream reconfiguration when libavfilter is disabled
Implement lazy initialization of the image resample context, so that the initialization code does not need to be duplicated. Also manage the case in which resample/size change mid-stream. For each packet the code computes if resampling is needed. Previously the resample check was done only at the initialization, in case size/format changed and no resample was detected at the init stage ffmpeg was silently exiting.
Diffstat (limited to 'ffmpeg.c')
-rw-r--r--ffmpeg.c41
1 files changed, 17 insertions, 24 deletions
diff --git a/ffmpeg.c b/ffmpeg.c
index 0169674b9a..d074489763 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -1204,14 +1204,28 @@ static void do_video_out(AVFormatContext *s,
ist->file_index, ist->index,
ost->resample_width, ost->resample_height, avcodec_get_pix_fmt_name(ost->resample_pix_fmt),
dec->width , dec->height , avcodec_get_pix_fmt_name(dec->pix_fmt));
- if(!ost->video_resample)
- ffmpeg_exit(1);
+ ost->resample_width = dec->width;
+ ost->resample_height = dec->height;
+ ost->resample_pix_fmt = dec->pix_fmt;
}
#if !CONFIG_AVFILTER
+ ost->video_resample = dec->width != enc->width ||
+ dec->height != enc->height ||
+ dec->pix_fmt != enc->pix_fmt;
+
if (ost->video_resample) {
final_picture = &ost->pict_tmp;
- if (resample_changed) {
+ if (!ost->img_resample_ctx || resample_changed) {
+ /* initialize the destination picture */
+ if (!ost->pict_tmp.data[0]) {
+ avcodec_get_frame_defaults(&ost->pict_tmp);
+ if (avpicture_alloc((AVPicture *)&ost->pict_tmp, enc->pix_fmt,
+ enc->width, enc->height)) {
+ fprintf(stderr, "Cannot allocate temp picture, check pix fmt\n");
+ ffmpeg_exit(1);
+ }
+ }
/* initialize a new scaler context */
sws_freeContext(ost->img_resample_ctx);
sws_flags = av_get_int(sws_opts, "sws_flags", NULL);
@@ -2290,27 +2304,6 @@ static int transcode(AVFormatContext **output_files,
codec->height != icodec->height ||
codec->pix_fmt != icodec->pix_fmt;
if (ost->video_resample) {
-#if !CONFIG_AVFILTER
- avcodec_get_frame_defaults(&ost->pict_tmp);
- if(avpicture_alloc((AVPicture*)&ost->pict_tmp, codec->pix_fmt,
- codec->width, codec->height)) {
- fprintf(stderr, "Cannot allocate temp picture, check pix fmt\n");
- ffmpeg_exit(1);
- }
- sws_flags = av_get_int(sws_opts, "sws_flags", NULL);
- ost->img_resample_ctx = sws_getContext(
- icodec->width,
- icodec->height,
- icodec->pix_fmt,
- codec->width,
- codec->height,
- codec->pix_fmt,
- sws_flags, NULL, NULL, NULL);
- if (ost->img_resample_ctx == NULL) {
- fprintf(stderr, "Cannot get resampling context\n");
- ffmpeg_exit(1);
- }
-#endif
codec->bits_per_raw_sample= frame_bits_per_raw_sample;
}
ost->resample_height = icodec->height;