History

avconv: fix -force_key_frames

parse_forced_keyframes() relies in encoder timebase being set, so call it from transcode_init() after it is known.

Anton Khirnov committed 14 years ago

Commit 19ad5671 parent ea1c5011 file · +32 −27Browse files

Unified · Split

avconv.c+32−27
@@ -270,6 +270,7 @@ typedef struct OutputStream { · 269 unmodified lines
270270 int64_t *forced_kf_pts;
271271 int forced_kf_count;
272272 int forced_kf_index;
273+ char *forced_keyframes;
273274
274275 FILE *logfile;
275276
@@ -1062,6 +1063,7 @@ void exit_program(int ret) · 786 unmodified lines
10621063 }
10631064 output_streams[i]->bitstream_filters = NULL;
10641065
1066+ av_freep(&output_streams[i]->forced_keyframes);
10651067 av_freep(&output_streams[i]->avfilter);
10661068 av_freep(&output_streams[i]->filtered_frame);
10671069 av_freep(&output_streams[i]);
@@ -2327,6 +2329,29 @@ static InputStream *get_input_stream(OutputStream *ost) · 1259 unmodified lines
23272329 return NULL;
23282330 }
23292331
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+
23302355 static int transcode_init(void)
23312356 {
23322357 int ret = 0, i, j, k;
@@ -2528,6 +2553,9 @@ static int transcode_init(void) · 195 unmodified lines
25282553 codec->bits_per_raw_sample = 0;
25292554 }
25302555
2556+ if (ost->forced_keyframes)
2557+ parse_forced_key_frames(ost->forced_keyframes, ost,
2558+ ost->st->codec);
25312559 break;
25322560 case AVMEDIA_TYPE_SUBTITLE:
25332561 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
36453673 return 0;
36463674 }
36473675
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−
36713676 static uint8_t *get_line(AVIOContext *s)
36723677 {
36733678 AVIOContext *line;
@@ -3865,7 +3870,7 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) · 191 unmodified lines
38653870
38663871 if (!ost->stream_copy) {
38673872 const char *p = NULL;
3868− char *forced_key_frames = NULL, *frame_rate = NULL, *frame_size = NULL;
3873+ char *frame_rate = NULL, *frame_size = NULL;
38693874 char *frame_aspect_ratio = NULL, *frame_pix_fmt = NULL;
38703875 char *intra_matrix = NULL, *inter_matrix = NULL;
38713876 const char *filters = "null";
@@ -3949,9 +3954,9 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc) · 77 unmodified lines
39493954 }
39503955 }
39513956
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);
39553960
39563961 MATCH_PER_STREAM_OPT(force_fps, i, ost->force_fps, oc, st);
39573962

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t