diff options
Diffstat (limited to 'libavformat/matroskaenc.c')
-rw-r--r-- | libavformat/matroskaenc.c | 302 |
1 files changed, 151 insertions, 151 deletions
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 0546686d8e..2be0629309 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -486,7 +486,7 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tra for (j = 0; j < cues->num_entries - i && entry[j].pts == pts; j++) { int tracknum = entry[j].stream_idx; av_assert0(tracknum>=0 && tracknum<num_tracks); - if (tracks[tracknum].has_cue && s->streams[tracknum]->codec->codec_type != AVMEDIA_TYPE_SUBTITLE) + if (tracks[tracknum].has_cue && s->streams[tracknum]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) continue; tracks[tracknum].has_cue = 1; ctp_nb ++; @@ -502,7 +502,7 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tra for (j = 0; j < cues->num_entries - i && entry[j].pts == pts; j++) { int tracknum = entry[j].stream_idx; av_assert0(tracknum>=0 && tracknum<num_tracks); - if (tracks[tracknum].has_cue && s->streams[tracknum]->codec->codec_type != AVMEDIA_TYPE_SUBTITLE) + if (tracks[tracknum].has_cue && s->streams[tracknum]->codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) continue; tracks[tracknum].has_cue = 1; track_positions = start_ebml_master(pb, MATROSKA_ID_CUETRACKPOSITION, MAX_CUETRACKPOS_SIZE); @@ -521,19 +521,19 @@ static int64_t mkv_write_cues(AVFormatContext *s, mkv_cues *cues, mkv_track *tra return currentpos; } -static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, AVCodecContext *codec) +static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par) { const uint8_t *header_start[3]; int header_len[3]; int first_header_size; int j; - if (codec->codec_id == AV_CODEC_ID_VORBIS) + if (par->codec_id == AV_CODEC_ID_VORBIS) first_header_size = 30; else first_header_size = 42; - if (avpriv_split_xiph_headers(codec->extradata, codec->extradata_size, + if (avpriv_split_xiph_headers(par->extradata, par->extradata_size, first_header_size, header_start, header_len) < 0) { av_log(s, AV_LOG_ERROR, "Extradata corrupt.\n"); return -1; @@ -549,22 +549,22 @@ static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, AVCodecContex return 0; } -static int put_wv_codecpriv(AVIOContext *pb, AVCodecContext *codec) +static int put_wv_codecpriv(AVIOContext *pb, AVCodecParameters *par) { - if (codec->extradata && codec->extradata_size == 2) - avio_write(pb, codec->extradata, 2); + if (par->extradata && par->extradata_size == 2) + avio_write(pb, par->extradata, 2); else avio_wl16(pb, 0x403); // fallback to the version mentioned in matroska specs return 0; } static int put_flac_codecpriv(AVFormatContext *s, - AVIOContext *pb, AVCodecContext *codec) + AVIOContext *pb, AVCodecParameters *par) { - int write_comment = (codec->channel_layout && - !(codec->channel_layout & ~0x3ffffULL) && - !ff_flac_is_native_layout(codec->channel_layout)); - int ret = ff_flac_write_header(pb, codec->extradata, codec->extradata_size, + int write_comment = (par->channel_layout && + !(par->channel_layout & ~0x3ffffULL) && + !ff_flac_is_native_layout(par->channel_layout)); + int ret = ff_flac_write_header(pb, par->extradata, par->extradata_size, !write_comment); if (ret < 0) @@ -577,7 +577,7 @@ static int put_flac_codecpriv(AVFormatContext *s, uint8_t buf[32], *data, *p; int64_t len; - snprintf(buf, sizeof(buf), "0x%"PRIx64, codec->channel_layout); + snprintf(buf, sizeof(buf), "0x%"PRIx64, par->channel_layout); av_dict_set(&dict, "WAVEFORMATEXTENSIBLE_CHANNEL_MASK", buf, 0); len = ff_vorbiscomment_length(dict, vendor); @@ -605,13 +605,13 @@ static int put_flac_codecpriv(AVFormatContext *s, return 0; } -static int get_aac_sample_rates(AVFormatContext *s, AVCodecContext *codec, +static int get_aac_sample_rates(AVFormatContext *s, AVCodecParameters *par, int *sample_rate, int *output_sample_rate) { MPEG4AudioConfig mp4ac; - if (avpriv_mpeg4audio_get_config(&mp4ac, codec->extradata, - codec->extradata_size * 8, 1) < 0) { + if (avpriv_mpeg4audio_get_config(&mp4ac, par->extradata, + par->extradata_size * 8, 1) < 0) { av_log(s, AV_LOG_ERROR, "Error parsing AAC extradata, unable to determine samplerate.\n"); return AVERROR(EINVAL); @@ -623,48 +623,48 @@ static int get_aac_sample_rates(AVFormatContext *s, AVCodecContext *codec, } static int mkv_write_native_codecprivate(AVFormatContext *s, - AVCodecContext *codec, + AVCodecParameters *par, AVIOContext *dyn_cp) { - switch (codec->codec_id) { + switch (par->codec_id) { case AV_CODEC_ID_VORBIS: case AV_CODEC_ID_THEORA: - return put_xiph_codecpriv(s, dyn_cp, codec); + return put_xiph_codecpriv(s, dyn_cp, par); case AV_CODEC_ID_FLAC: - return put_flac_codecpriv(s, dyn_cp, codec); + return put_flac_codecpriv(s, dyn_cp, par); case AV_CODEC_ID_WAVPACK: - return put_wv_codecpriv(dyn_cp, codec); + return put_wv_codecpriv(dyn_cp, par); case AV_CODEC_ID_H264: - return ff_isom_write_avcc(dyn_cp, codec->extradata, - codec->extradata_size); + return ff_isom_write_avcc(dyn_cp, par->extradata, + par->extradata_size); case AV_CODEC_ID_HEVC: - ff_isom_write_hvcc(dyn_cp, codec->extradata, - codec->extradata_size, 0); + ff_isom_write_hvcc(dyn_cp, par->extradata, + par->extradata_size, 0); return 0; case AV_CODEC_ID_ALAC: - if (codec->extradata_size < 36) { + if (par->extradata_size < 36) { av_log(s, AV_LOG_ERROR, "Invalid extradata found, ALAC expects a 36-byte " "QuickTime atom."); return AVERROR_INVALIDDATA; } else - avio_write(dyn_cp, codec->extradata + 12, - codec->extradata_size - 12); + avio_write(dyn_cp, par->extradata + 12, + par->extradata_size - 12); break; default: - if (codec->codec_id == AV_CODEC_ID_PRORES && - ff_codec_get_id(ff_codec_movvideo_tags, codec->codec_tag) == AV_CODEC_ID_PRORES) { - avio_wl32(dyn_cp, codec->codec_tag); - } else if (codec->extradata_size && codec->codec_id != AV_CODEC_ID_TTA) - avio_write(dyn_cp, codec->extradata, codec->extradata_size); + if (par->codec_id == AV_CODEC_ID_PRORES && + ff_codec_get_id(ff_codec_movvideo_tags, par->codec_tag) == AV_CODEC_ID_PRORES) { + avio_wl32(dyn_cp, par->codec_tag); + } else if (par->extradata_size && par->codec_id != AV_CODEC_ID_TTA) + avio_write(dyn_cp, par->extradata, par->extradata_size); } return 0; } static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, - AVCodecContext *codec, int native_id, - int qt_id) + AVCodecParameters *par, + int native_id, int qt_id) { AVIOContext *dyn_cp; uint8_t *codecpriv; @@ -675,52 +675,52 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, return ret; if (native_id) { - ret = mkv_write_native_codecprivate(s, codec, dyn_cp); - } else if (codec->codec_type == AVMEDIA_TYPE_VIDEO) { + ret = mkv_write_native_codecprivate(s, par, dyn_cp); + } else if (par->codec_type == AVMEDIA_TYPE_VIDEO) { if (qt_id) { - if (!codec->codec_tag) - codec->codec_tag = ff_codec_get_tag(ff_codec_movvideo_tags, - codec->codec_id); - if (codec->extradata_size) { - if ( ff_codec_get_id(ff_codec_movvideo_tags, codec->codec_tag) == codec->codec_id - && ff_codec_get_id(ff_codec_movvideo_tags, AV_RL32(codec->extradata + 4)) != codec->codec_id + if (!par->codec_tag) + par->codec_tag = ff_codec_get_tag(ff_codec_movvideo_tags, + par->codec_id); + if (par->extradata_size) { + if ( ff_codec_get_id(ff_codec_movvideo_tags, par->codec_tag) == par->codec_id + && ff_codec_get_id(ff_codec_movvideo_tags, AV_RL32(par->extradata + 4)) != par->codec_id ) { int i; - avio_wb32(dyn_cp, 0x5a + codec->extradata_size); - avio_wl32(dyn_cp, codec->codec_tag); + avio_wb32(dyn_cp, 0x5a + par->extradata_size); + avio_wl32(dyn_cp, par->codec_tag); for(i = 0; i < 0x5a - 8; i++) avio_w8(dyn_cp, 0); } - avio_write(dyn_cp, codec->extradata, codec->extradata_size); + avio_write(dyn_cp, par->extradata, par->extradata_size); } } else { - if (!ff_codec_get_tag(ff_codec_bmp_tags, codec->codec_id)) + if (!ff_codec_get_tag(ff_codec_bmp_tags, par->codec_id)) av_log(s, AV_LOG_WARNING, "codec %s is not supported by this format\n", - avcodec_get_name(codec->codec_id)); + avcodec_get_name(par->codec_id)); - if (!codec->codec_tag) - codec->codec_tag = ff_codec_get_tag(ff_codec_bmp_tags, - codec->codec_id); - if (!codec->codec_tag && codec->codec_id != AV_CODEC_ID_RAWVIDEO) { + if (!par->codec_tag) + par->codec_tag = ff_codec_get_tag(ff_codec_bmp_tags, + par->codec_id); + if (!par->codec_tag && par->codec_id != AV_CODEC_ID_RAWVIDEO) { av_log(s, AV_LOG_ERROR, "No bmp codec tag found for codec %s\n", - avcodec_get_name(codec->codec_id)); + avcodec_get_name(par->codec_id)); ret = AVERROR(EINVAL); } - ff_put_bmp_header(dyn_cp, codec, ff_codec_bmp_tags, 0, 0); + ff_put_bmp_header(dyn_cp, par, ff_codec_bmp_tags, 0, 0); } - } else if (codec->codec_type == AVMEDIA_TYPE_AUDIO) { + } else if (par->codec_type == AVMEDIA_TYPE_AUDIO) { unsigned int tag; - tag = ff_codec_get_tag(ff_codec_wav_tags, codec->codec_id); + tag = ff_codec_get_tag(ff_codec_wav_tags, par->codec_id); if (!tag) { av_log(s, AV_LOG_ERROR, "No wav codec tag found for codec %s\n", - avcodec_get_name(codec->codec_id)); + avcodec_get_name(par->codec_id)); ret = AVERROR(EINVAL); } - if (!codec->codec_tag) - codec->codec_tag = tag; + if (!par->codec_tag) + par->codec_tag = tag; - ff_put_wav_header(dyn_cp, codec, FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX); + ff_put_wav_header(s, dyn_cp, par, FF_PUT_WAV_HEADER_FORCE_WAVEFORMATEX); } codecpriv_size = avio_close_dyn_buf(dyn_cp, &codecpriv); @@ -731,28 +731,28 @@ static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, return ret; } -static int mkv_write_video_color(AVIOContext *pb, AVCodecContext *codec, AVStream *st) { +static int mkv_write_video_color(AVIOContext *pb, AVCodecParameters *par, AVStream *st) { int side_data_size = 0; const uint8_t *side_data = av_stream_get_side_data( st, AV_PKT_DATA_MASTERING_DISPLAY_METADATA, &side_data_size); ebml_master colorinfo = start_ebml_master(pb, MATROSKA_ID_VIDEOCOLOR, 0); - if (codec->color_trc != AVCOL_TRC_UNSPECIFIED && - codec->color_trc < AVCOL_TRC_NB) { + if (par->color_trc != AVCOL_TRC_UNSPECIFIED && + par->color_trc < AVCOL_TRC_NB) { put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORTRANSFERCHARACTERISTICS, - codec->color_trc); + par->color_trc); } - if (codec->colorspace != AVCOL_SPC_UNSPECIFIED && - codec->colorspace < AVCOL_SPC_NB) { - put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORMATRIXCOEFF, codec->colorspace); + if (par->color_space != AVCOL_SPC_UNSPECIFIED && + par->color_space < AVCOL_SPC_NB) { + put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORMATRIXCOEFF, par->color_space); } - if (codec->color_primaries != AVCOL_PRI_UNSPECIFIED && - codec->color_primaries < AVCOL_PRI_NB) { - put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORPRIMARIES, codec->color_primaries); + if (par->color_primaries != AVCOL_PRI_UNSPECIFIED && + par->color_primaries < AVCOL_PRI_NB) { + put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORPRIMARIES, par->color_primaries); } - if (codec->color_range != AVCOL_RANGE_UNSPECIFIED && - codec->color_range < AVCOL_RANGE_NB) { - put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORRANGE, codec->color_range); + if (par->color_range != AVCOL_RANGE_UNSPECIFIED && + par->color_range < AVCOL_RANGE_NB) { + put_ebml_uint(pb, MATROSKA_ID_VIDEOCOLORRANGE, par->color_range); } if (side_data_size == sizeof(AVMasteringDisplayMetadata)) { ebml_master meta_element = start_ebml_master( @@ -892,34 +892,34 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, int i, AVIOContext *pb, int default_stream_exists) { AVStream *st = s->streams[i]; - AVCodecContext *codec = st->codec; + AVCodecParameters *par = st->codecpar; ebml_master subinfo, track; int native_id = 0; int qt_id = 0; - int bit_depth = av_get_bits_per_sample(codec->codec_id); - int sample_rate = codec->sample_rate; + int bit_depth = av_get_bits_per_sample(par->codec_id); + int sample_rate = par->sample_rate; int output_sample_rate = 0; int display_width_div = 1; int display_height_div = 1; int j, ret; AVDictionaryEntry *tag; - if (codec->codec_type == AVMEDIA_TYPE_ATTACHMENT) { + if (par->codec_type == AVMEDIA_TYPE_ATTACHMENT) { mkv->have_attachments = 1; return 0; } - if (!bit_depth && codec->codec_id != AV_CODEC_ID_ADPCM_G726) { - if (codec->bits_per_raw_sample) - bit_depth = codec->bits_per_raw_sample; + if (!bit_depth && par->codec_id != AV_CODEC_ID_ADPCM_G726) { + if (par->bits_per_coded_sample) + bit_depth = par->bits_per_coded_sample; else - bit_depth = av_get_bytes_per_sample(codec->sample_fmt) << 3; + bit_depth = av_get_bytes_per_sample(par->format) << 3; } if (!bit_depth) - bit_depth = codec->bits_per_coded_sample; + bit_depth = par->bits_per_coded_sample; - if (codec->codec_id == AV_CODEC_ID_AAC) { - ret = get_aac_sample_rates(s, codec, &sample_rate, &output_sample_rate); + if (par->codec_id == AV_CODEC_ID_AAC) { + ret = get_aac_sample_rates(s, par, &sample_rate, &output_sample_rate); if (ret < 0) return ret; } @@ -934,7 +934,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, if ((tag = av_dict_get(st->metadata, "title", NULL, 0))) put_ebml_string(pb, MATROSKA_ID_TRACKNAME, tag->value); tag = av_dict_get(st->metadata, "language", NULL, 0); - if (mkv->mode != MODE_WEBM || codec->codec_id != AV_CODEC_ID_WEBVTT) { + if (mkv->mode != MODE_WEBM || par->codec_id != AV_CODEC_ID_WEBVTT) { put_ebml_string(pb, MATROSKA_ID_TRACKLANGUAGE, tag && tag->value ? tag->value:"und"); } else if (tag && tag->value) { put_ebml_string(pb, MATROSKA_ID_TRACKLANGUAGE, tag->value); @@ -948,7 +948,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, if (st->disposition & AV_DISPOSITION_FORCED) put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGFORCED, 1); - if (mkv->mode == MODE_WEBM && codec->codec_id == AV_CODEC_ID_WEBVTT) { + if (mkv->mode == MODE_WEBM && par->codec_id == AV_CODEC_ID_WEBVTT) { const char *codec_id; if (st->disposition & AV_DISPOSITION_CAPTIONS) { codec_id = "D_WEBVTT/CAPTIONS"; @@ -968,13 +968,13 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, // look for a codec ID string specific to mkv to use, // if none are found, use AVI codes for (j = 0; ff_mkv_codec_tags[j].id != AV_CODEC_ID_NONE; j++) { - if (ff_mkv_codec_tags[j].id == codec->codec_id) { + if (ff_mkv_codec_tags[j].id == par->codec_id) { put_ebml_string(pb, MATROSKA_ID_CODECID, ff_mkv_codec_tags[j].str); native_id = 1; break; } } - if (codec->codec_id == AV_CODEC_ID_RAWVIDEO && !codec->codec_tag) { + if (par->codec_id == AV_CODEC_ID_RAWVIDEO && !par->codec_tag) { if (mkv->allow_raw_vfw) { native_id = 0; } else { @@ -985,50 +985,50 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, } } - if (codec->codec_type == AVMEDIA_TYPE_AUDIO && codec->initial_padding && codec->codec_id == AV_CODEC_ID_OPUS) { - int64_t codecdelay = av_rescale_q(codec->initial_padding, + if (par->codec_type == AVMEDIA_TYPE_AUDIO && par->initial_padding && par->codec_id == AV_CODEC_ID_OPUS) { + int64_t codecdelay = av_rescale_q(par->initial_padding, (AVRational){ 1, 48000 }, (AVRational){ 1, 1000000000 }); if (codecdelay < 0) { av_log(s, AV_LOG_ERROR, "Initial padding is invalid\n"); return AVERROR(EINVAL); } -// mkv->tracks[i].ts_offset = av_rescale_q(codec->initial_padding, -// (AVRational){ 1, codec->sample_rate }, +// mkv->tracks[i].ts_offset = av_rescale_q(par->initial_padding, +// (AVRational){ 1, par->sample_rate }, // st->time_base); put_ebml_uint(pb, MATROSKA_ID_CODECDELAY, codecdelay); } - if (codec->codec_id == AV_CODEC_ID_OPUS) { + if (par->codec_id == AV_CODEC_ID_OPUS) { put_ebml_uint(pb, MATROSKA_ID_SEEKPREROLL, OPUS_SEEK_PREROLL); } - if (mkv->mode == MODE_WEBM && !(codec->codec_id == AV_CODEC_ID_VP8 || - codec->codec_id == AV_CODEC_ID_VP9 || - codec->codec_id == AV_CODEC_ID_OPUS || - codec->codec_id == AV_CODEC_ID_VORBIS || - codec->codec_id == AV_CODEC_ID_WEBVTT)) { + if (mkv->mode == MODE_WEBM && !(par->codec_id == AV_CODEC_ID_VP8 || + par->codec_id == AV_CODEC_ID_VP9 || + par->codec_id == AV_CODEC_ID_OPUS || + par->codec_id == AV_CODEC_ID_VORBIS || + par->codec_id == AV_CODEC_ID_WEBVTT)) { av_log(s, AV_LOG_ERROR, "Only VP8 or VP9 video and Vorbis or Opus audio and WebVTT subtitles are supported for WebM.\n"); return AVERROR(EINVAL); } - switch (codec->codec_type) { + switch (par->codec_type) { case AVMEDIA_TYPE_VIDEO: put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_VIDEO); if( st->avg_frame_rate.num > 0 && st->avg_frame_rate.den > 0 - && av_cmp_q(av_inv_q(st->avg_frame_rate), codec->time_base) > 0) + && av_cmp_q(av_inv_q(st->avg_frame_rate), st->time_base) > 0) put_ebml_uint(pb, MATROSKA_ID_TRACKDEFAULTDURATION, 1000000000LL * st->avg_frame_rate.den / st->avg_frame_rate.num); else - put_ebml_uint(pb, MATROSKA_ID_TRACKDEFAULTDURATION, 1000000000LL * codec->time_base.num / codec->time_base.den); + put_ebml_uint(pb, MATROSKA_ID_TRACKDEFAULTDURATION, 1000000000LL * st->time_base.num / st->time_base.den); if (!native_id && - ff_codec_get_tag(ff_codec_movvideo_tags, codec->codec_id) && - ((!ff_codec_get_tag(ff_codec_bmp_tags, codec->codec_id) && codec->codec_id != AV_CODEC_ID_RAWVIDEO) || - codec->codec_id == AV_CODEC_ID_SVQ1 || - codec->codec_id == AV_CODEC_ID_SVQ3 || - codec->codec_id == AV_CODEC_ID_CINEPAK)) + ff_codec_get_tag(ff_codec_movvideo_tags, par->codec_id) && + ((!ff_codec_get_tag(ff_codec_bmp_tags, par->codec_id) && par->codec_id != AV_CODEC_ID_RAWVIDEO) || + par->codec_id == AV_CODEC_ID_SVQ1 || + par->codec_id == AV_CODEC_ID_SVQ3 || + par->codec_id == AV_CODEC_ID_CINEPAK)) qt_id = 1; if (qt_id) @@ -1042,8 +1042,8 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKVIDEO, 0); // XXX: interlace flag? - put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELWIDTH , codec->width); - put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELHEIGHT, codec->height); + put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELWIDTH , par->width); + put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELHEIGHT, par->height); // check both side data and metadata for stereo information, // write the result to the bitstream if any is found @@ -1055,31 +1055,31 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, if (((tag = av_dict_get(st->metadata, "alpha_mode", NULL, 0)) && atoi(tag->value)) || ((tag = av_dict_get( s->metadata, "alpha_mode", NULL, 0)) && atoi(tag->value)) || - (codec->pix_fmt == AV_PIX_FMT_YUVA420P)) { + (par->format == AV_PIX_FMT_YUVA420P)) { put_ebml_uint(pb, MATROSKA_ID_VIDEOALPHAMODE, 1); } // write DisplayWidth and DisplayHeight, they contain the size of // a single source view and/or the display aspect ratio if (st->sample_aspect_ratio.num) { - int64_t d_width = av_rescale(codec->width, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den); + int64_t d_width = av_rescale(par->width, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den); if (d_width > INT_MAX) { av_log(s, AV_LOG_ERROR, "Overflow in display width\n"); return AVERROR(EINVAL); } put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH , d_width / display_width_div); - put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, codec->height / display_height_div); + put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, par->height / display_height_div); } else if (display_width_div != 1 || display_height_div != 1) { - put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH , codec->width / display_width_div); - put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, codec->height / display_height_div); + put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH , par->width / display_width_div); + put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, par->height / display_height_div); } - if (codec->codec_id == AV_CODEC_ID_RAWVIDEO) { - uint32_t color_space = av_le2ne32(codec->codec_tag); + if (par->codec_id == AV_CODEC_ID_RAWVIDEO) { + uint32_t color_space = av_le2ne32(par->codec_tag); put_ebml_binary(pb, MATROSKA_ID_VIDEOCOLORSPACE, &color_space, sizeof(color_space)); } if (s->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL) { - mkv_write_video_color(pb, codec, st); + mkv_write_video_color(pb, par, st); } end_ebml_master(pb, subinfo); break; @@ -1092,7 +1092,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, put_ebml_string(pb, MATROSKA_ID_CODECID, "A_MS/ACM"); subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKAUDIO, 0); - put_ebml_uint (pb, MATROSKA_ID_AUDIOCHANNELS , codec->channels); + put_ebml_uint (pb, MATROSKA_ID_AUDIOCHANNELS , par->channels); put_ebml_float (pb, MATROSKA_ID_AUDIOSAMPLINGFREQ, sample_rate); if (output_sample_rate) put_ebml_float(pb, MATROSKA_ID_AUDIOOUTSAMPLINGFREQ, output_sample_rate); @@ -1103,11 +1103,11 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, case AVMEDIA_TYPE_SUBTITLE: if (!native_id) { - av_log(s, AV_LOG_ERROR, "Subtitle codec %d is not supported.\n", codec->codec_id); + av_log(s, AV_LOG_ERROR, "Subtitle codec %d is not supported.\n", par->codec_id); return AVERROR(ENOSYS); } - if (mkv->mode != MODE_WEBM || codec->codec_id != AV_CODEC_ID_WEBVTT) + if (mkv->mode != MODE_WEBM || par->codec_id != AV_CODEC_ID_WEBVTT) native_id = MATROSKA_TRACK_TYPE_SUBTITLE; put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, native_id); @@ -1117,8 +1117,8 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv, return AVERROR(EINVAL); } - if (mkv->mode != MODE_WEBM || codec->codec_id != AV_CODEC_ID_WEBVTT) { - ret = mkv_write_codecprivate(s, pb, codec, native_id, qt_id); + if (mkv->mode != MODE_WEBM || par->codec_id != AV_CODEC_ID_WEBVTT) { + ret = mkv_write_codecprivate(s, pb, par, native_id, qt_id); if (ret < 0) return ret; } @@ -1383,7 +1383,7 @@ static int mkv_write_attachments(AVFormatContext *s) const char *mimetype = NULL; uint64_t fileuid; - if (st->codec->codec_type != AVMEDIA_TYPE_ATTACHMENT) + if (st->codecpar->codec_type != AVMEDIA_TYPE_ATTACHMENT) continue; attached_file = start_ebml_master(pb, MATROSKA_ID_ATTACHEDFILE, 0); @@ -1397,15 +1397,15 @@ static int mkv_write_attachments(AVFormatContext *s) put_ebml_string(pb, MATROSKA_ID_FILENAME, t->value); if (t = av_dict_get(st->metadata, "mimetype", NULL, 0)) mimetype = t->value; - else if (st->codec->codec_id != AV_CODEC_ID_NONE ) { + else if (st->codecpar->codec_id != AV_CODEC_ID_NONE ) { int i; for (i = 0; ff_mkv_mime_tags[i].id != AV_CODEC_ID_NONE; i++) - if (ff_mkv_mime_tags[i].id == st->codec->codec_id) { + if (ff_mkv_mime_tags[i].id == st->codecpar->codec_id) { mimetype = ff_mkv_mime_tags[i].str; break; } for (i = 0; ff_mkv_image_mime_tags[i].id != AV_CODEC_ID_NONE; i++) - if (ff_mkv_image_mime_tags[i].id == st->codec->codec_id) { + if (ff_mkv_image_mime_tags[i].id == st->codecpar->codec_id) { mimetype = ff_mkv_image_mime_tags[i].str; break; } @@ -1422,7 +1422,7 @@ static int mkv_write_attachments(AVFormatContext *s) if (!sha) return AVERROR(ENOMEM); av_sha_init(sha, 160); - av_sha_update(sha, st->codec->extradata, st->codec->extradata_size); + av_sha_update(sha, st->codecpar->extradata, st->codecpar->extradata_size); av_sha_final(sha, digest); av_free(sha); fileuid = AV_RL64(digest); @@ -1433,7 +1433,7 @@ static int mkv_write_attachments(AVFormatContext *s) fileuid, i); put_ebml_string(pb, MATROSKA_ID_FILEMIMETYPE, mimetype); - put_ebml_binary(pb, MATROSKA_ID_FILEDATA, st->codec->extradata, st->codec->extradata_size); + put_ebml_binary(pb, MATROSKA_ID_FILEDATA, st->codecpar->extradata, st->codecpar->extradata_size); put_ebml_uint(pb, MATROSKA_ID_FILEUID, fileuid); end_ebml_master(pb, attached_file); } @@ -1462,18 +1462,18 @@ static int mkv_write_header(AVFormatContext *s) version = 4; for (i = 0; i < s->nb_streams; i++) { - if (s->streams[i]->codec->codec_id == AV_CODEC_ID_ATRAC3 || - s->streams[i]->codec->codec_id == AV_CODEC_ID_COOK || - s->streams[i]->codec->codec_id == AV_CODEC_ID_RA_288 || - s->streams[i]->codec->codec_id == AV_CODEC_ID_SIPR || - s->streams[i]->codec->codec_id == AV_CODEC_ID_RV10 || - s->streams[i]->codec->codec_id == AV_CODEC_ID_RV20) { + if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_ATRAC3 || + s->streams[i]->codecpar->codec_id == AV_CODEC_ID_COOK || + s->streams[i]->codecpar->codec_id == AV_CODEC_ID_RA_288 || + s->streams[i]->codecpar->codec_id == AV_CODEC_ID_SIPR || + s->streams[i]->codecpar->codec_id == AV_CODEC_ID_RV10 || + s->streams[i]->codecpar->codec_id == AV_CODEC_ID_RV20) { av_log(s, AV_LOG_ERROR, "The Matroska muxer does not yet support muxing %s\n", - avcodec_get_name(s->streams[i]->codec->codec_id)); + avcodec_get_name(s->streams[i]->codecpar->codec_id)); return AVERROR_PATCHWELCOME; } - if (s->streams[i]->codec->codec_id == AV_CODEC_ID_OPUS || + if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_OPUS || av_dict_get(s->streams[i]->metadata, "stereo_mode", NULL, 0) || av_dict_get(s->streams[i]->metadata, "alpha_mode", NULL, 0)) version = 4; @@ -1684,7 +1684,7 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb, unsigned int blockid, AVPacket *pkt, int keyframe) { MatroskaMuxContext *mkv = s->priv_data; - AVCodecContext *codec = s->streams[pkt->stream_index]->codec; + AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar; uint8_t *data = NULL, *side_data = NULL; int offset = 0, size = pkt->size, side_data_size = 0; int64_t ts = mkv->tracks[pkt->stream_index].write_dts ? pkt->dts : pkt->pts; @@ -1697,14 +1697,14 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb, "pts %" PRId64 ", dts %" PRId64 ", duration %" PRId64 ", keyframe %d\n", avio_tell(pb), pkt->size, pkt->pts, pkt->dts, pkt->duration, keyframe != 0); - if (codec->codec_id == AV_CODEC_ID_H264 && codec->extradata_size > 0 && - (AV_RB24(codec->extradata) == 1 || AV_RB32(codec->extradata) == 1)) + if (par->codec_id == AV_CODEC_ID_H264 && par->extradata_size > 0 && + (AV_RB24(par->extradata) == 1 || AV_RB32(par->extradata) == 1)) ff_avc_parse_nal_units_buf(pkt->data, &data, &size); - else if (codec->codec_id == AV_CODEC_ID_HEVC && codec->extradata_size > 6 && - (AV_RB24(codec->extradata) == 1 || AV_RB32(codec->extradata) == 1)) + else if (par->codec_id == AV_CODEC_ID_HEVC && par->extradata_size > 6 && + (AV_RB24(par->extradata) == 1 || AV_RB32(par->extradata) == 1)) /* extradata is Annex B, assume the bitstream is too and convert it */ ff_hevc_annexb2mp4_buf(pkt->data, &data, &size, 0, NULL); - else if (codec->codec_id == AV_CODEC_ID_WAVPACK) { + else if (par->codec_id == AV_CODEC_ID_WAVPACK) { int ret = mkv_strip_wavpack(pkt->data, &data, &size); if (ret < 0) { av_log(s, AV_LOG_ERROR, "Error stripping a WavPack packet.\n"); @@ -1713,7 +1713,7 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb, } else data = pkt->data; - if (codec->codec_id == AV_CODEC_ID_PRORES && size >= 8) { + if (par->codec_id == AV_CODEC_ID_PRORES && size >= 8) { /* Matroska specification requires to remove the first QuickTime atom */ size -= 8; @@ -1726,7 +1726,7 @@ static void mkv_write_block(AVFormatContext *s, AVIOContext *pb, if (side_data && side_data_size >= 10) { discard_padding = av_rescale_q(AV_RL32(side_data + 4), - (AVRational){1, codec->sample_rate}, + (AVRational){1, par->sample_rate}, (AVRational){1, 1000000000}); } @@ -1858,7 +1858,7 @@ static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt, int add_ { MatroskaMuxContext *mkv = s->priv_data; AVIOContext *pb = s->pb; - AVCodecContext *codec = s->streams[pkt->stream_index]->codec; + AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar; int keyframe = !!(pkt->flags & AV_PKT_FLAG_KEY); int duration = pkt->duration; int ret; @@ -1900,14 +1900,14 @@ static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt, int add_ relative_packet_pos = avio_tell(s->pb) - mkv->cluster.pos; - if (codec->codec_type != AVMEDIA_TYPE_SUBTITLE) { + if (par->codec_type != AVMEDIA_TYPE_SUBTITLE) { mkv_write_block(s, pb, MATROSKA_ID_SIMPLEBLOCK, pkt, keyframe); - if (s->pb->seekable && (codec->codec_type == AVMEDIA_TYPE_VIDEO && keyframe || add_cue)) { + if (s->pb->seekable && (par->codec_type == AVMEDIA_TYPE_VIDEO && keyframe || add_cue)) { ret = mkv_add_cuepoint(mkv->cues, pkt->stream_index, dash_tracknum, ts, mkv->cluster_pos, relative_packet_pos, -1); if (ret < 0) return ret; } } else { - if (codec->codec_id == AV_CODEC_ID_WEBVTT) { + if (par->codec_id == AV_CODEC_ID_WEBVTT) { duration = mkv_write_vtt_blocks(s, pb, pkt); } else { ebml_master blockgroup = start_ebml_master(pb, MATROSKA_ID_BLOCKGROUP, @@ -1947,7 +1947,7 @@ FF_ENABLE_DEPRECATION_WARNINGS static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt) { MatroskaMuxContext *mkv = s->priv_data; - int codec_type = s->streams[pkt->stream_index]->codec->codec_type; + int codec_type = s->streams[pkt->stream_index]->codecpar->codec_type; int keyframe = !!(pkt->flags & AV_PKT_FLAG_KEY); int cluster_size; int64_t cluster_time; @@ -2183,10 +2183,10 @@ static int mkv_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt) int ret = 1; AVStream *st = s->streams[pkt->stream_index]; - if (st->codec->codec_id == AV_CODEC_ID_AAC) { + if (st->codecpar->codec_id == AV_CODEC_ID_AAC) { if (pkt->size > 2 && (AV_RB16(pkt->data) & 0xfff0) == 0xfff0) ret = ff_stream_add_bitstream_filter(st, "aac_adtstoasc", NULL); - } else if (st->codec->codec_id == AV_CODEC_ID_VP9) { + } else if (st->codecpar->codec_id == AV_CODEC_ID_VP9) { ret = ff_stream_add_bitstream_filter(st, "vp9_superframe", NULL); } |