parse_forced_keyframes() relies in encoder timebase being set, so call it from transcode_init() after it is known.
Unified · Split
| @@ -270,6 +270,7 @@ typedef struct OutputStream { · 269 unmodified lines | ||
| 270 | 270 | int64_t *forced_kf_pts; |
| 271 | 271 | int forced_kf_count; |
| 272 | 272 | int forced_kf_index; |
| 273 | + char *forced_keyframes; | |
| 273 | 274 | |
| 274 | 275 | FILE *logfile; |
| 275 | 276 | |
| @@ -1062,6 +1063,7 @@ void exit_program(int ret) · 786 unmodified lines | ||
| 1062 | 1063 | } |
| 1063 | 1064 | output_streams[i]->bitstream_filters = NULL; |
| 1064 | 1065 | |
| 1066 | + av_freep(&output_streams[i]->forced_keyframes); | |
| 1065 | 1067 | av_freep(&output_streams[i]->avfilter); |
| 1066 | 1068 | av_freep(&output_streams[i]->filtered_frame); |
| 1067 | 1069 | av_freep(&output_streams[i]); |
| @@ -2327,6 +2329,29 @@ static InputStream *get_input_stream(OutputStream *ost) · 1259 unmodified lines | ||
| 2327 | 2329 | return NULL; |
| 2328 | 2330 | } |
| 2329 | 2331 | |
| 2332 | +static void parse_forced_key_frames(char *kf, OutputStream *ost, | |
| 2333 | + AVCodecContext *avctx) | |
| 2334 | +{ | |
| 2335 | + char *p; | |
| 2336 | + int n = 1, i; | |
| 2337 | + int64_t t; | |
| 2338 | + | |
| 2339 | + for (p = kf; *p; p++) | |
| 2340 | + if (*p == ',') | |
| 2341 | + n++; | |
| 2342 | + ost->forced_kf_count = n; | |
| 2343 | + ost->forced_kf_pts = av_malloc(sizeof(*ost->forced_kf_pts) * n); | |
| 2344 | + if (!ost->forced_kf_pts) { | |
| 2345 | + av_log(NULL, AV_LOG_FATAL, "Could not allocate forced key frames array.\n"); | |
| 2346 | + exit_program(1); | |
| 2347 | + } | |
| 2348 | + for (i = 0; i < n; i++) { | |
| 2349 | + p = i ? strchr(p, ',') + 1 : kf; | |
| 2350 | + t = parse_time_or_die("force_key_frames", p, 1); | |
| 2351 | + ost->forced_kf_pts[i] = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base); | |
| 2352 | + } | |
| 2353 | +} | |
| 2354 | + | |
| 2330 | 2355 | static int transcode_init(void) |
| 2331 | 2356 | { |
| 2332 | 2357 | int ret = 0, i, j, k; |
| @@ -2528,6 +2553,9 @@ static int transcode_init(void) · 195 unmodified lines | ||
| 2528 | 2553 | codec->bits_per_raw_sample = 0; |
| 2529 | 2554 | } |
| 2530 | 2555 | |
| 2556 | + if (ost->forced_keyframes) | |
| 2557 | + parse_forced_key_frames(ost->forced_keyframes, ost, | |
| 2558 | + ost->st->codec); | |
| 2531 | 2559 | break; |
| 2532 | 2560 | case AVMEDIA_TYPE_SUBTITLE: |
| 2533 | 2561 | codec->time_base = (AVRational){1, 1000}; |
| @@ -3645,29 +3673,6 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena · 1111 unmodified lines | ||
| 3645 | 3673 | return 0; |
| 3646 | 3674 | } |
| 3647 | 3675 | |
| 3648 | −static void parse_forced_key_frames(char *kf, OutputStream *ost, | |
| 3649 | − AVCodecContext *avctx) | |
| 3650 | −{ | |
| 3651 | − char *p; | |
| 3652 | − int n = 1, i; | |
| 3653 | − int64_t t; | |
| 3654 | − | |
| 3655 | − for (p = kf; *p; p++) | |
| 3656 | − if (*p == ',') | |
| 3657 | − n++; | |
| 3658 | − ost->forced_kf_count = n; | |
| 3659 | − ost->forced_kf_pts = av_malloc(sizeof(*ost->forced_kf_pts) * n); | |
| 3660 | − if (!ost->forced_kf_pts) { | |
| 3661 | − av_log(NULL, AV_LOG_FATAL, "Could not allocate forced key frames array.\n"); | |
| 3662 | − exit_program(1); | |
| 3663 | − } | |
| 3664 | − for (i = 0; i < n; i++) { | |
| 3665 | − p = i ? strchr(p, ',') + 1 : kf; | |
| 3666 | − t = parse_time_or_die("force_key_frames", p, 1); | |
| 3667 | − ost->forced_kf_pts[i] = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base); | |
| 3668 | − } | |
| 3669 | −} | |
| 3670 | − | |
| 3671 | 3676 | static uint8_t *get_line(AVIOContext *s) |
| 3672 | 3677 | { |
| 3673 | 3678 | AVIOContext *line; |
| @@ -3865,7 +3870,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) · 191 unmodified lines | ||
| 3865 | 3870 | |
| 3866 | 3871 | if (!ost->stream_copy) { |
| 3867 | 3872 | const char *p = NULL; |
| 3868 | − char *forced_key_frames = NULL, *frame_rate = NULL, *frame_size = NULL; | |
| 3873 | + char *frame_rate = NULL, *frame_size = NULL; | |
| 3869 | 3874 | char *frame_aspect_ratio = NULL, *frame_pix_fmt = NULL; |
| 3870 | 3875 | char *intra_matrix = NULL, *inter_matrix = NULL; |
| 3871 | 3876 | const char *filters = "null"; |
| @@ -3949,9 +3954,9 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) · 77 unmodified lines | ||
| 3949 | 3954 | } |
| 3950 | 3955 | } |
| 3951 | 3956 | |
| 3952 | − MATCH_PER_STREAM_OPT(forced_key_frames, str, forced_key_frames, oc, st); | |
| 3953 | − if (forced_key_frames) | |
| 3954 | − parse_forced_key_frames(forced_key_frames, ost, video_enc); | |
| 3957 | + MATCH_PER_STREAM_OPT(forced_key_frames, str, ost->forced_keyframes, oc, st); | |
| 3958 | + if (ost->forced_keyframes) | |
| 3959 | + ost->forced_keyframes = av_strdup(ost->forced_keyframes); | |
| 3955 | 3960 | |
| 3956 | 3961 | MATCH_PER_STREAM_OPT(force_fps, i, ost->force_fps, oc, st); |
| 3957 | 3962 | |