Commit 65f7aee6 authored by Michael Niedermayer's avatar Michael Niedermayer

ffmpeg: add option to control copying of frames prior to start.

Normally we discard things prior to the intended start
for stream copy this is not always possible, and its not done by default
this option allows discarding to be enabled

this is primarely usefull when transcoding a video and stream copying an
audio stream.
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent d3704464
...@@ -1340,6 +1340,10 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p ...@@ -1340,6 +1340,10 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
!ost->copy_initial_nonkeyframes) !ost->copy_initial_nonkeyframes)
return; return;
if (!ost->frame_number && ist->pts < of->start_time &&
!ost->copy_prior_start)
return;
if (of->recording_time != INT64_MAX && if (of->recording_time != INT64_MAX &&
ist->pts >= of->recording_time + of->start_time) { ist->pts >= of->recording_time + of->start_time) {
close_output_stream(ost); close_output_stream(ost);
......
...@@ -157,6 +157,8 @@ typedef struct OptionsContext { ...@@ -157,6 +157,8 @@ typedef struct OptionsContext {
int nb_presets; int nb_presets;
SpecifierOpt *copy_initial_nonkeyframes; SpecifierOpt *copy_initial_nonkeyframes;
int nb_copy_initial_nonkeyframes; int nb_copy_initial_nonkeyframes;
SpecifierOpt *copy_prior_start;
int nb_copy_prior_start;
SpecifierOpt *filters; SpecifierOpt *filters;
int nb_filters; int nb_filters;
SpecifierOpt *fix_sub_duration; SpecifierOpt *fix_sub_duration;
...@@ -326,6 +328,7 @@ typedef struct OutputStream { ...@@ -326,6 +328,7 @@ typedef struct OutputStream {
int stream_copy; int stream_copy;
const char *attachment_filename; const char *attachment_filename;
int copy_initial_nonkeyframes; int copy_initial_nonkeyframes;
int copy_prior_start;
int keep_pix_fmt; int keep_pix_fmt;
} OutputStream; } OutputStream;
......
...@@ -960,6 +960,9 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e ...@@ -960,6 +960,9 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e
ost->max_frames = INT64_MAX; ost->max_frames = INT64_MAX;
MATCH_PER_STREAM_OPT(max_frames, i64, ost->max_frames, oc, st); MATCH_PER_STREAM_OPT(max_frames, i64, ost->max_frames, oc, st);
ost->copy_prior_start = -1;
MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc ,st);
MATCH_PER_STREAM_OPT(bitstream_filters, str, bsf, oc, st); MATCH_PER_STREAM_OPT(bitstream_filters, str, bsf, oc, st);
while (bsf) { while (bsf) {
if (next = strchr(bsf, ',')) if (next = strchr(bsf, ','))
...@@ -2316,6 +2319,8 @@ const OptionDef options[] = { ...@@ -2316,6 +2319,8 @@ const OptionDef options[] = {
"exit on error", "error" }, "exit on error", "error" },
{ "copyinkf", OPT_BOOL | OPT_EXPERT | OPT_SPEC, { .off = OFFSET(copy_initial_nonkeyframes) }, { "copyinkf", OPT_BOOL | OPT_EXPERT | OPT_SPEC, { .off = OFFSET(copy_initial_nonkeyframes) },
"copy initial non-keyframes" }, "copy initial non-keyframes" },
{ "copypriorss", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_SPEC, { .off = OFFSET(copy_prior_start) },
"copy or discard frames before start time" },
{ "frames", OPT_INT64 | HAS_ARG | OPT_SPEC, { .off = OFFSET(max_frames) }, { "frames", OPT_INT64 | HAS_ARG | OPT_SPEC, { .off = OFFSET(max_frames) },
"set the number of frames to record", "number" }, "set the number of frames to record", "number" },
{ "tag", OPT_STRING | HAS_ARG | OPT_SPEC | OPT_EXPERT,{ .off = OFFSET(codec_tags) }, { "tag", OPT_STRING | HAS_ARG | OPT_SPEC | OPT_EXPERT,{ .off = OFFSET(codec_tags) },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment