@@ -664,16 +664,16 @@ static bool ffmpeg_init_config_common(struct ff_config_param *params,
664664 av_dict_set (& params -> audio_opts , "audio_global_quality" , "50" , 0 );
665665
666666 /* TO-DO: detect if hwaccel is available and use it instead of the preset above
667- strlcpy(params->vcodec, "h264_nvenc", sizeof(params->vcodec));
668- strlcpy(params->acodec, "aac", sizeof(params->acodec));
667+ strlcpy(params->vcodec, "h264_nvenc", sizeof(params->vcodec));
668+ strlcpy(params->acodec, "aac", sizeof(params->acodec));
669669
670- av_dict_set(¶ms->video_opts, "preset", "llhp", 0);
671- av_dict_set(¶ms->video_opts, "tune", "zerolatency", 0);
672- av_dict_set(¶ms->video_opts, "zerolatency", "1", 0);
673- av_dict_set(¶ms->video_opts, "-rc-lookahead", "0", 0);
674- av_dict_set(¶ms->video_opts, "x264-params", "threads=0:intra-refresh=1:b-frames=0", 0);
675- av_dict_set(¶ms->audio_opts, "audio_global_quality", "100", 0);
676- */
670+ av_dict_set(¶ms->video_opts, "preset", "llhp", 0);
671+ av_dict_set(¶ms->video_opts, "tune", "zerolatency", 0);
672+ av_dict_set(¶ms->video_opts, "zerolatency", "1", 0);
673+ av_dict_set(¶ms->video_opts, "-rc-lookahead", "0", 0);
674+ av_dict_set(¶ms->video_opts, "x264-params", "threads=0:intra-refresh=1:b-frames=0", 0);
675+ av_dict_set(¶ms->audio_opts, "audio_global_quality", "100", 0);
676+ */
677677
678678 break ;
679679 default :
@@ -719,9 +719,9 @@ static bool ffmpeg_init_config_common(struct ff_config_param *params,
719719 video_stream_scale_factor : 1 ;
720720 else
721721 params -> scale_factor = 1 ;
722- if ( streaming_mode == STREAMING_MODE_YOUTUBE ||
723- streaming_mode == STREAMING_MODE_TWITCH ||
724- streaming_mode == STREAMING_MODE_FACEBOOK )
722+ if ( streaming_mode == STREAMING_MODE_YOUTUBE
723+ || streaming_mode == STREAMING_MODE_TWITCH
724+ || streaming_mode == STREAMING_MODE_FACEBOOK )
725725 strlcpy (params -> format , "flv" , sizeof (params -> format ));
726726 else
727727 strlcpy (params -> format , "mpegts" , sizeof (params -> format ));
@@ -835,7 +835,7 @@ static bool ffmpeg_init_muxer_pre(ffmpeg_t *handle)
835835#if !FFMPEG3
836836 ctx -> oformat = av_guess_format (NULL , ctx -> url , NULL );
837837#else
838- ctx -> oformat = av_guess_format (NULL , ctx -> filename , NULL );
838+ ctx -> oformat = av_guess_format (NULL , ctx -> filename , NULL );
839839#endif
840840
841841 if (!ctx -> oformat )
@@ -857,8 +857,8 @@ static bool ffmpeg_init_muxer_post(ffmpeg_t *handle)
857857 handle -> video .encoder );
858858
859859 avcodec_parameters_from_context (stream -> codecpar , handle -> video .codec );
860- stream -> time_base = handle -> video .codec -> time_base ;
861- handle -> muxer .vstream = stream ;
860+ stream -> time_base = handle -> video .codec -> time_base ;
861+ handle -> muxer .vstream = stream ;
862862 handle -> muxer .vstream -> sample_aspect_ratio =
863863 handle -> video .codec -> sample_aspect_ratio ;
864864
@@ -867,7 +867,7 @@ static bool ffmpeg_init_muxer_post(ffmpeg_t *handle)
867867 stream = avformat_new_stream (handle -> muxer .ctx ,
868868 handle -> audio .encoder );
869869 avcodec_parameters_from_context (stream -> codecpar , handle -> audio .codec );
870- stream -> time_base = handle -> audio .codec -> time_base ;
870+ stream -> time_base = handle -> audio .codec -> time_base ;
871871 handle -> muxer .astream = stream ;
872872 }
873873
@@ -890,7 +890,7 @@ static bool init_thread(ffmpeg_t *handle)
890890 handle -> params .channels * MAX_FRAMES / 60 ); /* Some arbitrary max size. */
891891 handle -> attr_fifo = fifo_new (sizeof (struct record_video_data ) * MAX_FRAMES );
892892 handle -> video_fifo = fifo_new (handle -> params .fb_width * handle -> params .fb_height *
893- handle -> video .pix_size * MAX_FRAMES );
893+ handle -> video .pix_size * MAX_FRAMES );
894894
895895 handle -> alive = true;
896896 handle -> can_sleep = true;
@@ -1042,8 +1042,8 @@ static void *ffmpeg_new(const struct record_params *params)
10421042 if (!ffmpeg_init_video (handle ))
10431043 goto error ;
10441044
1045- if (handle -> config .audio_enable &&
1046- !ffmpeg_init_audio (handle ,
1045+ if ( handle -> config .audio_enable
1046+ && !ffmpeg_init_audio (handle ,
10471047 params -> audio_resampler ))
10481048 goto error ;
10491049
@@ -1181,12 +1181,10 @@ static bool ffmpeg_push_audio(void *data,
11811181
11821182static bool encode_video (ffmpeg_t * handle , AVFrame * frame )
11831183{
1184- AVPacket * pkt ;
11851184 int ret ;
1186-
1187- pkt = handle -> pkt ;
1188- pkt -> data = handle -> video .outbuf ;
1189- pkt -> size = (int )handle -> video .outbuf_size ;
1185+ AVPacket * pkt = handle -> pkt ;
1186+ pkt -> data = handle -> video .outbuf ;
1187+ pkt -> size = (int )handle -> video .outbuf_size ;
11901188
11911189 ret = avcodec_send_frame (handle -> video .codec , frame );
11921190 if (ret < 0 )
@@ -1215,12 +1213,12 @@ static bool encode_video(ffmpeg_t *handle, AVFrame *frame)
12151213 }
12161214
12171215 pkt -> pts = av_rescale_q (pkt -> pts ,
1218- handle -> video .codec -> time_base ,
1219- handle -> muxer .vstream -> time_base );
1216+ handle -> video .codec -> time_base ,
1217+ handle -> muxer .vstream -> time_base );
12201218
12211219 pkt -> dts = av_rescale_q (pkt -> dts ,
1222- handle -> video .codec -> time_base ,
1223- handle -> muxer .vstream -> time_base );
1220+ handle -> video .codec -> time_base ,
1221+ handle -> muxer .vstream -> time_base );
12241222
12251223 pkt -> stream_index = handle -> muxer .vstream -> index ;
12261224
@@ -1340,17 +1338,15 @@ static void planarize_audio(ffmpeg_t *handle)
13401338
13411339static bool encode_audio (ffmpeg_t * handle , bool dry )
13421340{
1341+ int ret ;
13431342 AVFrame * frame ;
1344- AVPacket * pkt ;
13451343 int samples_size ;
1346- int ret ;
1344+ AVPacket * pkt = handle -> pkt ;
13471345
1348- pkt = handle -> pkt ;
1346+ pkt -> data = handle -> audio .outbuf ;
1347+ pkt -> size = (int )handle -> audio .outbuf_size ;
13491348
1350- pkt -> data = handle -> audio .outbuf ;
1351- pkt -> size = (int )handle -> audio .outbuf_size ;
1352-
1353- frame = av_frame_alloc ();
1349+ frame = av_frame_alloc ();
13541350
13551351 if (!frame )
13561352 return false;
@@ -1416,12 +1412,12 @@ static bool encode_audio(ffmpeg_t *handle, bool dry)
14161412 }
14171413
14181414 pkt -> pts = av_rescale_q (pkt -> pts ,
1419- handle -> audio .codec -> time_base ,
1420- handle -> muxer .astream -> time_base );
1415+ handle -> audio .codec -> time_base ,
1416+ handle -> muxer .astream -> time_base );
14211417
14221418 pkt -> dts = av_rescale_q (pkt -> dts ,
1423- handle -> audio .codec -> time_base ,
1424- handle -> muxer .astream -> time_base );
1419+ handle -> audio .codec -> time_base ,
1420+ handle -> muxer .astream -> time_base );
14251421
14261422 pkt -> stream_index = handle -> muxer .astream -> index ;
14271423
@@ -1573,12 +1569,6 @@ static void ffmpeg_flush_audio(ffmpeg_t *handle, void *audio_buf,
15731569 }
15741570
15751571 encode_audio (handle , true);
1576- }
1577-
1578- static void ffmpeg_flush_video (ffmpeg_t * handle )
1579- {
1580- encode_video (handle , NULL );
1581-
15821572}
15831573
15841574static void ffmpeg_flush_buffers (ffmpeg_t * handle )
@@ -1634,7 +1624,7 @@ static void ffmpeg_flush_buffers(ffmpeg_t *handle)
16341624 ffmpeg_flush_audio (handle , audio_buf , audio_buf_size );
16351625
16361626 /* Flush out last video. */
1637- ffmpeg_flush_video (handle );
1627+ encode_video (handle , NULL );
16381628
16391629 av_free (video_buf );
16401630 av_free (audio_buf );
0 commit comments