diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index 68c606f7..5a4c936d 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -156,10 +156,18 @@ void FFmpegReader::Open() if (pCodec == NULL) { throw InvalidCodec("A valid video codec could not be found for this file.", path); } + + // Init options + AVDictionary *opts = NULL; + av_dict_set(&opts, "strict", "experimental", 0); + // Open video codec - if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) + if (avcodec_open2(pCodecCtx, pCodec, &opts) < 0) throw InvalidCodec("A video codec was found, but could not be opened.", path); + // Free options + av_dict_free(&opts); + // Update the File Info struct with video details (if a video stream is found) UpdateVideoInfo(); } @@ -186,10 +194,18 @@ void FFmpegReader::Open() if (aCodec == NULL) { throw InvalidCodec("A valid audio codec could not be found for this file.", path); } + + // Init options + AVDictionary *opts = NULL; + av_dict_set(&opts, "strict", "experimental", 0); + // Open audio codec - if (avcodec_open2(aCodecCtx, aCodec, NULL) < 0) + if (avcodec_open2(aCodecCtx, aCodec, &opts) < 0) throw InvalidCodec("An audio codec was found, but could not be opened.", path); + // Free options + av_dict_free(&opts); + // Update the File Info struct with audio details (if an audio stream is found) UpdateAudioInfo(); } diff --git a/src/FFmpegWriter.cpp b/src/FFmpegWriter.cpp index b4fb83b8..4416040a 100644 --- a/src/FFmpegWriter.cpp +++ b/src/FFmpegWriter.cpp @@ -298,6 +298,9 @@ void FFmpegWriter::SetOption(StreamType stream, string name, string value) /// Determine if codec name is valid bool FFmpegWriter::IsValidCodec(string codec_name) { + // Initialize FFMpeg, and register all formats and codecs + av_register_all(); + // Find the codec (if any) if (avcodec_find_encoder_by_name(codec_name.c_str()) == NULL) return false; @@ -999,11 +1002,18 @@ void FFmpegWriter::open_audio(AVFormatContext *oc, AVStream *st) if (!codec) throw InvalidCodec("Could not find codec", path); + // Init options + AVDictionary *opts = NULL; + av_dict_set(&opts, "strict", "experimental", 0); + // Open the codec - if (avcodec_open2(audio_codec, codec, NULL) < 0) + if (avcodec_open2(audio_codec, codec, &opts) < 0) throw InvalidCodec("Could not open codec", path); AV_COPY_PARAMS_FROM_CONTEXT(st, audio_codec); + // Free options + av_dict_free(&opts); + // Calculate the size of the input frame (i..e how many samples per packet), and the output buffer // TODO: Ugly hack for PCM codecs (will be removed ASAP with new PCM support to compute the input frame size in samples if (audio_codec->frame_size <= 1) { @@ -1070,11 +1080,18 @@ void FFmpegWriter::open_video(AVFormatContext *oc, AVStream *st) if(video_codec->max_b_frames && video_codec->codec_id != AV_CODEC_ID_MPEG4 && video_codec->codec_id != AV_CODEC_ID_MPEG1VIDEO && video_codec->codec_id != AV_CODEC_ID_MPEG2VIDEO) video_codec->max_b_frames = 0; + // Init options + AVDictionary *opts = NULL; + av_dict_set(&opts, "strict", "experimental", 0); + /* open the codec */ - if (avcodec_open2(video_codec, codec, NULL) < 0) + if (avcodec_open2(video_codec, codec, &opts) < 0) throw InvalidCodec("Could not open codec", path); AV_COPY_PARAMS_FROM_CONTEXT(st, video_codec); + // Free options + av_dict_free(&opts); + // Add video metadata (if any) for(std::map::iterator iter = info.metadata.begin(); iter != info.metadata.end(); ++iter) {