]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/avienc.c
Merge commit '5b9cdf8cba114c41239bf0f9f5e0ccb6977d1c8d'
[ffmpeg] / libavformat / avienc.c
index 7a7abb87189a67164550efaef7cf656a0008c125..c908c21e4fc9c39332e949f10e1878b17a8a102d 100644 (file)
@@ -180,21 +180,21 @@ static int avi_write_counters(AVFormatContext *s, int riff_id)
     AVIContext *avi = s->priv_data;
     int n, au_byterate, au_ssize, au_scale, nb_frames = 0;
     int64_t file_size;
-    AVCodecContext *stream;
+    AVCodecParameters *par;
 
     file_size = avio_tell(pb);
     for (n = 0; n < s->nb_streams; n++) {
         AVIStream *avist = s->streams[n]->priv_data;
 
         av_assert0(avist->frames_hdr_strm);
-        stream = s->streams[n]->codec;
+        par = s->streams[n]->codecpar;
         avio_seek(pb, avist->frames_hdr_strm, SEEK_SET);
         ff_parse_specific_params(s->streams[n], &au_byterate, &au_ssize, &au_scale);
         if (au_ssize == 0)
             avio_wl32(pb, avist->packet_count);
         else
             avio_wl32(pb, avist->audio_strm_length / au_ssize);
-        if (stream->codec_type == AVMEDIA_TYPE_VIDEO)
+        if (par->codec_type == AVMEDIA_TYPE_VIDEO)
             nb_frames = FFMAX(nb_frames, avist->packet_count);
     }
     if (riff_id == 1) {
@@ -211,7 +211,7 @@ static void write_odml_master(AVFormatContext *s, int stream_index)
 {
     AVIOContext *pb = s->pb;
     AVStream *st = s->streams[stream_index];
-    AVCodecContext *enc = st->codec;
+    AVCodecParameters *par = st->codecpar;
     AVIStream *avist = st->priv_data;
     unsigned char tag[5];
     int j;
@@ -225,7 +225,7 @@ static void write_odml_master(AVFormatContext *s, int stream_index)
     avio_w8(pb, 0);     /* bIndexSubType (0 == frame index) */
     avio_w8(pb, 0);     /* bIndexType (0 == AVI_INDEX_OF_INDEXES) */
     avio_wl32(pb, 0);   /* nEntriesInUse (will fill out later on) */
-    ffio_wfourcc(pb, avi_stream2fourcc(tag, stream_index, enc->codec_type));
+    ffio_wfourcc(pb, avi_stream2fourcc(tag, stream_index, par->codec_type));
                         /* dwChunkId */
     avio_wl64(pb, 0);   /* dwReserved[3] */
     avio_wl32(pb, 0);   /* Must be 0.    */
@@ -239,7 +239,7 @@ static int avi_write_header(AVFormatContext *s)
     AVIContext *avi = s->priv_data;
     AVIOContext *pb = s->pb;
     int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale;
-    AVCodecContext *video_enc;
+    AVCodecParameters *video_par;
     AVStream *video_st = NULL;
     int64_t list1, list2, strh, strf;
     AVDictionaryEntry *t = NULL;
@@ -266,12 +266,12 @@ static int avi_write_header(AVFormatContext *s)
     avio_wl32(pb, 14 * 4);
     bitrate = 0;
 
-    video_enc = NULL;
+    video_par = NULL;
     for (n = 0; n < s->nb_streams; n++) {
-        AVCodecContext *codec = s->streams[n]->codec;
-        bitrate += codec->bit_rate;
-        if (codec->codec_type == AVMEDIA_TYPE_VIDEO) {
-            video_enc = codec;
+        AVCodecParameters *par = s->streams[n]->codecpar;
+        bitrate += par->bit_rate;
+        if (par->codec_type == AVMEDIA_TYPE_VIDEO) {
+            video_par = par;
             video_st = s->streams[n];
         }
     }
@@ -295,9 +295,9 @@ static int avi_write_header(AVFormatContext *s)
     avio_wl32(pb, 0); /* initial frame */
     avio_wl32(pb, s->nb_streams); /* nb streams */
     avio_wl32(pb, 1024 * 1024); /* suggested buffer size */
-    if (video_enc) {
-        avio_wl32(pb, video_enc->width);
-        avio_wl32(pb, video_enc->height);
+    if (video_par) {
+        avio_wl32(pb, video_par->width);
+        avio_wl32(pb, video_par->height);
     } else {
         avio_wl32(pb, 0);
         avio_wl32(pb, 0);
@@ -310,18 +310,18 @@ static int avi_write_header(AVFormatContext *s)
     /* stream list */
     for (i = 0; i < n; i++) {
         AVStream *st = s->streams[i];
-        AVCodecContext *enc = st->codec;
+        AVCodecParameters *par = st->codecpar;
         AVIStream *avist = st->priv_data;
         list2 = ff_start_tag(pb, "LIST");
         ffio_wfourcc(pb, "strl");
 
         /* stream generic header */
         strh = ff_start_tag(pb, "strh");
-        switch (enc->codec_type) {
+        switch (par->codec_type) {
         case AVMEDIA_TYPE_SUBTITLE:
             // XSUB subtitles behave like video tracks, other subtitles
             // are not (yet) supported.
-            if (enc->codec_id != AV_CODEC_ID_XSUB) {
+            if (par->codec_id != AV_CODEC_ID_XSUB) {
                 av_log(s, AV_LOG_ERROR,
                        "Subtitle streams other than DivX XSUB are not supported by the AVI muxer.\n");
                 return AVERROR_PATCHWELCOME;
@@ -339,9 +339,9 @@ static int avi_write_header(AVFormatContext *s)
             ffio_wfourcc(pb, "dats");
             break;
         }
-        if (enc->codec_type == AVMEDIA_TYPE_VIDEO ||
-            enc->codec_id == AV_CODEC_ID_XSUB)
-            avio_wl32(pb, enc->codec_tag);
+        if (par->codec_type == AVMEDIA_TYPE_VIDEO ||
+            par->codec_id == AV_CODEC_ID_XSUB)
+            avio_wl32(pb, par->codec_tag);
         else
             avio_wl32(pb, 1);
         avist->strh_flags_offset = avio_tell(pb);
@@ -352,14 +352,14 @@ static int avi_write_header(AVFormatContext *s)
 
         ff_parse_specific_params(st, &au_byterate, &au_ssize, &au_scale);
 
-        if (   enc->codec_type == AVMEDIA_TYPE_VIDEO
-            && enc->codec_id != AV_CODEC_ID_XSUB
+        if (   par->codec_type == AVMEDIA_TYPE_VIDEO
+            && par->codec_id != AV_CODEC_ID_XSUB
             && au_byterate > 1000LL*au_scale) {
             au_byterate = 600;
             au_scale    = 1;
         }
         avpriv_set_pts_info(st, 64, au_scale, au_byterate);
-        if (enc->codec_id == AV_CODEC_ID_XSUB)
+        if (par->codec_id == AV_CODEC_ID_XSUB)
             au_scale = au_byterate = 0;
 
         avio_wl32(pb, au_scale); /* scale */
@@ -375,57 +375,57 @@ static int avi_write_header(AVFormatContext *s)
             avio_wl32(pb, 0);  /* length, XXX: filled later */
 
         /* suggested buffer size, is set to largest chunk size in avi_write_trailer */
-        if (enc->codec_type == AVMEDIA_TYPE_VIDEO)
+        if (par->codec_type == AVMEDIA_TYPE_VIDEO)
             avio_wl32(pb, 1024 * 1024);
-        else if (enc->codec_type == AVMEDIA_TYPE_AUDIO)
+        else if (par->codec_type == AVMEDIA_TYPE_AUDIO)
             avio_wl32(pb, 12 * 1024);
         else
             avio_wl32(pb, 0);
         avio_wl32(pb, -1); /* quality */
         avio_wl32(pb, au_ssize); /* sample size */
         avio_wl32(pb, 0);
-        avio_wl16(pb, enc->width);
-        avio_wl16(pb, enc->height);
+        avio_wl16(pb, par->width);
+        avio_wl16(pb, par->height);
         ff_end_tag(pb, strh);
 
-        if (enc->codec_type != AVMEDIA_TYPE_DATA) {
+        if (par->codec_type != AVMEDIA_TYPE_DATA) {
             int ret, flags;
             enum AVPixelFormat pix_fmt;
 
             strf = ff_start_tag(pb, "strf");
-            switch (enc->codec_type) {
+            switch (par->codec_type) {
             case AVMEDIA_TYPE_SUBTITLE:
                 /* XSUB subtitles behave like video tracks, other subtitles
                  * are not (yet) supported. */
-                if (enc->codec_id != AV_CODEC_ID_XSUB)
+                if (par->codec_id != AV_CODEC_ID_XSUB)
                     break;
             case AVMEDIA_TYPE_VIDEO:
                 /* WMP expects RGB 5:5:5 rawvideo in avi to have bpp set to 16. */
-                if (  !enc->codec_tag
-                    && enc->codec_id == AV_CODEC_ID_RAWVIDEO
-                    && enc->pix_fmt == AV_PIX_FMT_RGB555LE
-                    && enc->bits_per_coded_sample == 15)
-                    enc->bits_per_coded_sample = 16;
+                if (  !par->codec_tag
+                    && par->codec_id == AV_CODEC_ID_RAWVIDEO
+                    && par->format == AV_PIX_FMT_RGB555LE
+                    && par->bits_per_coded_sample == 15)
+                    par->bits_per_coded_sample = 16;
                 avist->pal_offset = avio_tell(pb) + 40;
-                ff_put_bmp_header(pb, enc, ff_codec_bmp_tags, 0, 0);
+                ff_put_bmp_header(pb, par, ff_codec_bmp_tags, 0, 0);
                 pix_fmt = avpriv_find_pix_fmt(avpriv_pix_fmt_bps_avi,
-                                              enc->bits_per_coded_sample);
-                if (   !enc->codec_tag
-                    && enc->codec_id == AV_CODEC_ID_RAWVIDEO
-                    && enc->pix_fmt != pix_fmt
-                    && enc->pix_fmt != AV_PIX_FMT_NONE)
+                                              par->bits_per_coded_sample);
+                if (   !par->codec_tag
+                    && par->codec_id == AV_CODEC_ID_RAWVIDEO
+                    && par->format != pix_fmt
+                    && par->format != AV_PIX_FMT_NONE)
                     av_log(s, AV_LOG_ERROR, "%s rawvideo cannot be written to avi, output file will be unreadable\n",
-                          av_get_pix_fmt_name(enc->pix_fmt));
+                          av_get_pix_fmt_name(par->format));
                 break;
             case AVMEDIA_TYPE_AUDIO:
                 flags = (avi->write_channel_mask == 0) ? FF_PUT_WAV_HEADER_SKIP_CHANNELMASK : 0;
-                if ((ret = ff_put_wav_header(pb, enc, flags)) < 0)
+                if ((ret = ff_put_wav_header(s, pb, par, flags)) < 0)
                     return ret;
                 break;
             default:
                 av_log(s, AV_LOG_ERROR,
                     "Invalid or not supported codec type '%s' found in the input\n",
-                    (char *)av_x_if_null(av_get_media_type_string(enc->codec_type), "?"));
+                    (char *)av_x_if_null(av_get_media_type_string(par->codec_type), "?"));
                 return AVERROR(EINVAL);
             }
             ff_end_tag(pb, strf);
@@ -433,7 +433,7 @@ static int avi_write_header(AVFormatContext *s)
                 ff_riff_write_info_tag(s->pb, "strn", t->value);
                 t = NULL;
             }
-            if (enc->codec_id == AV_CODEC_ID_XSUB
+            if (par->codec_id == AV_CODEC_ID_XSUB
             && (t = av_dict_get(s->streams[i]->metadata, "language", NULL, 0))) {
                 const char* langstr = av_convert_lang_to(t->value, AV_LANG_ISO639_1);
                 t = NULL;
@@ -451,13 +451,13 @@ static int avi_write_header(AVFormatContext *s)
             write_odml_master(s, i);
         }
 
-        if (enc->codec_type == AVMEDIA_TYPE_VIDEO   &&
+        if (par->codec_type == AVMEDIA_TYPE_VIDEO   &&
             st->sample_aspect_ratio.num > 0 &&
             st->sample_aspect_ratio.den > 0) {
             int vprp       = ff_start_tag(pb, "vprp");
             AVRational dar = av_mul_q(st->sample_aspect_ratio,
-                                      (AVRational) { enc->width,
-                                                     enc->height });
+                                      (AVRational) { par->width,
+                                                     par->height });
             int num, den;
             av_reduce(&num, &den, dar.num, dar.den, 0xFFFF);
 
@@ -465,18 +465,18 @@ static int avi_write_header(AVFormatContext *s)
             avio_wl32(pb, 0); // video standard = unknown
             // TODO: should be avg_frame_rate
             avio_wl32(pb, (2LL*st->time_base.den + st->time_base.num - 1) / (2LL * st->time_base.num));
-            avio_wl32(pb, enc->width);
-            avio_wl32(pb, enc->height);
+            avio_wl32(pb, par->width);
+            avio_wl32(pb, par->height);
             avio_wl16(pb, den);
             avio_wl16(pb, num);
-            avio_wl32(pb, enc->width);
-            avio_wl32(pb, enc->height);
+            avio_wl32(pb, par->width);
+            avio_wl32(pb, par->height);
             avio_wl32(pb, 1); // progressive FIXME
 
-            avio_wl32(pb, enc->height);
-            avio_wl32(pb, enc->width);
-            avio_wl32(pb, enc->height);
-            avio_wl32(pb, enc->width);
+            avio_wl32(pb, par->height);
+            avio_wl32(pb, par->width);
+            avio_wl32(pb, par->height);
+            avio_wl32(pb, par->width);
             avio_wl32(pb, 0);
             avio_wl32(pb, 0);
 
@@ -544,7 +544,7 @@ static void update_odml_entry(AVFormatContext *s, int stream_index, int64_t ix,
     avio_wl64(pb, ix);                    /* qwOffset */
     avio_wl32(pb, size);                  /* dwSize */
     ff_parse_specific_params(s->streams[stream_index], &au_byterate, &au_ssize, &au_scale);
-    if (s->streams[stream_index]->codec->codec_type == AVMEDIA_TYPE_AUDIO && au_ssize > 0) {
+    if (s->streams[stream_index]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && au_ssize > 0) {
         uint32_t audio_segm_size = (avist->audio_strm_length - avist->indexes.audio_strm_offset);
         if ((audio_segm_size % au_ssize > 0) && !avist->sample_requested) {
             avpriv_request_sample(s, "OpenDML index duration for audio packets with partial frames");
@@ -586,7 +586,7 @@ static int avi_write_ix(AVFormatContext *s)
         AVIStream *avist = s->streams[i]->priv_data;
         int64_t ix;
 
-        avi_stream2fourcc(tag, i, s->streams[i]->codec->codec_type);
+        avi_stream2fourcc(tag, i, s->streams[i]->codecpar->codec_type);
         ix_tag[3] = '0' + i;
 
         /* Writing AVI OpenDML leaf index chunk */
@@ -654,7 +654,7 @@ static int avi_write_idx1(AVFormatContext *s)
                     ffio_wfourcc(pb, ie->tag);
                 else {
                     avi_stream2fourcc(tag, stream_id,
-                                  s->streams[stream_id]->codec->codec_type);
+                                  s->streams[stream_id]->codecpar->codec_type);
                     ffio_wfourcc(pb, tag);
                 }
                 avio_wl32(pb, ie->flags);
@@ -673,11 +673,11 @@ static int avi_write_idx1(AVFormatContext *s)
 static int write_skip_frames(AVFormatContext *s, int stream_index, int64_t dts)
 {
     AVIStream *avist    = s->streams[stream_index]->priv_data;
-    AVCodecContext *enc = s->streams[stream_index]->codec;
+    AVCodecParameters *par = s->streams[stream_index]->codecpar;
 
     ff_dlog(s, "dts:%s packet_count:%d stream_index:%d\n", av_ts2str(dts), avist->packet_count, stream_index);
-    while (enc->block_align == 0 && dts != AV_NOPTS_VALUE &&
-           dts > avist->packet_count && enc->codec_id != AV_CODEC_ID_XSUB && avist->packet_count) {
+    while (par->block_align == 0 && dts != AV_NOPTS_VALUE &&
+           dts > avist->packet_count && par->codec_id != AV_CODEC_ID_XSUB && avist->packet_count) {
         AVPacket empty_packet;
 
         if (dts - avist->packet_count > 60000) {
@@ -699,10 +699,10 @@ static int write_skip_frames(AVFormatContext *s, int stream_index, int64_t dts)
 static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
 {
     const int stream_index = pkt->stream_index;
-    AVCodecContext *enc = s->streams[stream_index]->codec;
+    AVCodecParameters *par = s->streams[stream_index]->codecpar;
     int ret;
 
-    if (enc->codec_id == AV_CODEC_ID_H264 && enc->codec_tag == MKTAG('H','2','6','4') && pkt->size) {
+    if (par->codec_id == AV_CODEC_ID_H264 && par->codec_tag == MKTAG('H','2','6','4') && pkt->size) {
         ret = ff_check_h264_startcode(s, s->streams[stream_index], pkt);
         if (ret < 0)
             return ret;
@@ -714,27 +714,27 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
     if (!pkt->size)
         return avi_write_packet_internal(s, pkt); /* Passthrough */
 
-    if (enc->codec_type == AVMEDIA_TYPE_VIDEO) {
+    if (par->codec_type == AVMEDIA_TYPE_VIDEO) {
         AVIStream *avist = s->streams[stream_index]->priv_data;
         AVIOContext *pb  = s->pb;
         AVPacket *opkt   = pkt;
-        if (enc->codec_id == AV_CODEC_ID_RAWVIDEO && enc->codec_tag == 0) {
-            int64_t bpc = enc->bits_per_coded_sample != 15 ? enc->bits_per_coded_sample : 16;
-            int expected_stride = ((enc->width * bpc + 31) >> 5)*4;
-            ret = ff_reshuffle_raw_rgb(s, &pkt, enc, expected_stride);
+        if (par->codec_id == AV_CODEC_ID_RAWVIDEO && par->codec_tag == 0) {
+            int64_t bpc = par->bits_per_coded_sample != 15 ? par->bits_per_coded_sample : 16;
+            int expected_stride = ((par->width * bpc + 31) >> 5)*4;
+            ret = ff_reshuffle_raw_rgb(s, &pkt, par, expected_stride);
             if (ret < 0)
                 return ret;
         } else
             ret = 0;
-        if (enc->pix_fmt == AV_PIX_FMT_PAL8) {
+        if (par->format == AV_PIX_FMT_PAL8) {
             int ret2 = ff_get_packet_palette(s, opkt, ret, avist->palette);
             if (ret2 < 0)
                 return ret2;
             if (ret2) {
-                int pal_size = 1 << enc->bits_per_coded_sample;
+                int pal_size = 1 << par->bits_per_coded_sample;
                 int pc_tag, i;
 
-                av_assert0(enc->bits_per_coded_sample >= 0 && enc->bits_per_coded_sample <= 8);
+                av_assert0(par->bits_per_coded_sample >= 0 && par->bits_per_coded_sample <= 8);
 
                 if (pb->seekable && avist->pal_offset) {
                     int64_t cur_offset = avio_tell(pb);
@@ -749,7 +749,7 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
                 }
                 if (memcmp(avist->palette, avist->old_palette, pal_size * 4)) {
                     unsigned char tag[5];
-                    avi_stream2fourcc(tag, stream_index, enc->codec_type);
+                    avi_stream2fourcc(tag, stream_index, par->codec_type);
                     tag[2] = 'p'; tag[3] = 'c';
                     if (s->pb->seekable) {
                         int ret;
@@ -797,7 +797,7 @@ static int avi_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
     AVIContext *avi     = s->priv_data;
     AVIOContext *pb     = s->pb;
     AVIStream *avist    = s->streams[stream_index]->priv_data;
-    AVCodecContext *enc = s->streams[stream_index]->codec;
+    AVCodecParameters *par = s->streams[stream_index]->codecpar;
 
     if (pkt->dts != AV_NOPTS_VALUE)
         avist->last_dts = pkt->dts + pkt->duration;
@@ -817,10 +817,10 @@ static int avi_write_packet_internal(AVFormatContext *s, AVPacket *pkt)
         avi->movi_list = avi_start_new_riff(s, pb, "AVIX", "movi");
     }
 
-    avi_stream2fourcc(tag, stream_index, enc->codec_type);
+    avi_stream2fourcc(tag, stream_index, par->codec_type);
     if (pkt->flags & AV_PKT_FLAG_KEY)
         flags = 0x10;
-    if (enc->codec_type == AVMEDIA_TYPE_AUDIO)
+    if (par->codec_type == AVMEDIA_TYPE_AUDIO)
         avist->audio_strm_length += size;
 
     if (s->pb->seekable) {
@@ -868,15 +868,15 @@ static int avi_write_trailer(AVFormatContext *s)
             avio_skip(pb, 16);
 
             for (n = nb_frames = 0; n < s->nb_streams; n++) {
-                AVCodecContext *stream = s->streams[n]->codec;
+                AVCodecParameters *par = s->streams[n]->codecpar;
                 AVIStream *avist       = s->streams[n]->priv_data;
 
-                if (stream->codec_type == AVMEDIA_TYPE_VIDEO) {
+                if (par->codec_type == AVMEDIA_TYPE_VIDEO) {
                     if (nb_frames < avist->packet_count)
                         nb_frames = avist->packet_count;
                 } else {
-                    if (stream->codec_id == AV_CODEC_ID_MP2 ||
-                        stream->codec_id == AV_CODEC_ID_MP3)
+                    if (par->codec_id == AV_CODEC_ID_MP2 ||
+                        par->codec_id == AV_CODEC_ID_MP3)
                         nb_frames += avist->packet_count;
                 }
             }