@@ -170,6 +170,7 @@ static bool create_video_stream(struct ffmpeg_data *data)
170170 enum AVPixelFormat closest_format ;
171171 AVCodecContext * context ;
172172 struct obs_video_info ovi ;
173+ const enum AVPixelFormat * pix_fmts = NULL ;
173174
174175 if (!obs_get_video_info (& ovi )) {
175176 ffmpeg_log_error (LOG_WARNING , data , "No active video" );
@@ -180,28 +181,35 @@ static bool create_video_stream(struct ffmpeg_data *data)
180181 data -> config .video_encoder ))
181182 return false;
182183
183- closest_format = data -> config .format ;
184- if (data -> vcodec -> pix_fmts ) {
185- const int has_alpha = closest_format == AV_PIX_FMT_BGRA ;
186- closest_format =
187- avcodec_find_best_pix_fmt_of_list (data -> vcodec -> pix_fmts , closest_format , has_alpha , NULL );
188- }
189-
190184 context = avcodec_alloc_context3 (data -> vcodec );
191185 context -> bit_rate = (int64_t )data -> config .video_bitrate * 1000 ;
192186 context -> width = data -> config .scale_width ;
193187 context -> height = data -> config .scale_height ;
194188 context -> time_base = (AVRational ){ovi .fps_den , ovi .fps_num };
195189 context -> framerate = (AVRational ){ovi .fps_num , ovi .fps_den };
196190 context -> gop_size = data -> config .gop_size ;
197- context -> pix_fmt = closest_format ;
198191 context -> color_range = data -> config .color_range ;
199192 context -> color_primaries = data -> config .color_primaries ;
200193 context -> color_trc = data -> config .color_trc ;
201194 context -> colorspace = data -> config .colorspace ;
202- context -> chroma_sample_location = determine_chroma_location (closest_format , data -> config .colorspace );
203195 context -> thread_count = 0 ;
204196
197+ #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT (61 , 13 , 100 )
198+ pix_fmts = data -> vcodec -> pix_fmts ;
199+ #else
200+ avcodec_get_supported_config (context , data -> vcodec , AV_CODEC_CONFIG_PIX_FORMAT , 0 , (const void * * )& pix_fmts ,
201+ NULL );
202+ #endif
203+
204+ closest_format = data -> config .format ;
205+ if (pix_fmts ) {
206+ const int has_alpha = closest_format == AV_PIX_FMT_BGRA ;
207+ closest_format = avcodec_find_best_pix_fmt_of_list (pix_fmts , closest_format , has_alpha , NULL );
208+ }
209+
210+ context -> pix_fmt = closest_format ;
211+ context -> chroma_sample_location = determine_chroma_location (closest_format , data -> config .colorspace );
212+
205213 data -> video -> time_base = context -> time_base ;
206214 data -> video -> avg_frame_rate = (AVRational ){ovi .fps_num , ovi .fps_den };
207215
@@ -305,6 +313,7 @@ static bool create_audio_stream(struct ffmpeg_data *data, int idx)
305313 AVStream * stream ;
306314 struct obs_audio_info aoi ;
307315 int channels ;
316+ const enum AVSampleFormat * sample_fmts = NULL ;
308317
309318 if (!obs_get_audio_info (& aoi )) {
310319 ffmpeg_log_error (LOG_WARNING , data , "No active audio" );
@@ -324,7 +333,14 @@ static bool create_audio_stream(struct ffmpeg_data *data, int idx)
324333 if (aoi .speakers == SPEAKERS_4POINT1 )
325334 context -> ch_layout = (AVChannelLayout )AV_CHANNEL_LAYOUT_4POINT1 ;
326335
327- context -> sample_fmt = data -> acodec -> sample_fmts ? data -> acodec -> sample_fmts [0 ] : AV_SAMPLE_FMT_FLTP ;
336+ #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT (61 , 13 , 100 )
337+ sample_fmts = data -> acodec -> sample_fmts ;
338+ #else
339+ avcodec_get_supported_config (context , data -> acodec , AV_CODEC_CONFIG_SAMPLE_FORMAT , 0 ,
340+ (const void * * )& sample_fmts , NULL );
341+ #endif
342+
343+ context -> sample_fmt = sample_fmts ? sample_fmts [0 ] : AV_SAMPLE_FMT_FLTP ;
328344
329345 stream -> time_base = context -> time_base ;
330346
0 commit comments