@@ -296,6 +296,18 @@ void FFmpegWriter::SetOption(StreamType stream, string name, string value)
296296
297297}
298298
299+ // / Determine if codec name is valid
300+ bool FFmpegWriter::IsValidCodec (string codec_name) {
301+ // Initialize FFMpeg, and register all formats and codecs
302+ av_register_all ();
303+
304+ // Find the codec (if any)
305+ if (avcodec_find_encoder_by_name (codec_name.c_str ()) == NULL )
306+ return false ;
307+ else
308+ return true ;
309+ }
310+
299311// Prepare & initialize streams and open codecs
300312void FFmpegWriter::PrepareStreams ()
301313{
@@ -990,11 +1002,18 @@ void FFmpegWriter::open_audio(AVFormatContext *oc, AVStream *st)
9901002 if (!codec)
9911003 throw InvalidCodec (" Could not find codec" , path);
9921004
1005+ // Init options
1006+ AVDictionary *opts = NULL ;
1007+ av_dict_set (&opts, " strict" , " experimental" , 0 );
1008+
9931009 // Open the codec
994- if (avcodec_open2 (audio_codec, codec, NULL ) < 0 )
1010+ if (avcodec_open2 (audio_codec, codec, &opts ) < 0 )
9951011 throw InvalidCodec (" Could not open codec" , path);
9961012 AV_COPY_PARAMS_FROM_CONTEXT (st, audio_codec);
9971013
1014+ // Free options
1015+ av_dict_free (&opts);
1016+
9981017 // Calculate the size of the input frame (i..e how many samples per packet), and the output buffer
9991018 // TODO: Ugly hack for PCM codecs (will be removed ASAP with new PCM support to compute the input frame size in samples
10001019 if (audio_codec->frame_size <= 1 ) {
@@ -1061,11 +1080,18 @@ void FFmpegWriter::open_video(AVFormatContext *oc, AVStream *st)
10611080 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)
10621081 video_codec->max_b_frames = 0 ;
10631082
1083+ // Init options
1084+ AVDictionary *opts = NULL ;
1085+ av_dict_set (&opts, " strict" , " experimental" , 0 );
1086+
10641087 /* open the codec */
1065- if (avcodec_open2 (video_codec, codec, NULL ) < 0 )
1088+ if (avcodec_open2 (video_codec, codec, &opts ) < 0 )
10661089 throw InvalidCodec (" Could not open codec" , path);
10671090 AV_COPY_PARAMS_FROM_CONTEXT (st, video_codec);
10681091
1092+ // Free options
1093+ av_dict_free (&opts);
1094+
10691095 // Add video metadata (if any)
10701096 for (std::map<string, string>::iterator iter = info.metadata .begin (); iter != info.metadata .end (); ++iter)
10711097 {
0 commit comments