[FFmpeg-devel] [PATCH]Add -skip_initial_bytes option (-sb)

Carl Eugen Hoyos cehoyos at ag.or.at
Fri Nov 16 16:33:16 CET 2012


Hi!

Attached patch implements ticket #1909 and adds a work-around for ticket 
#1812.
I absolutely wanted to call the option "-sb" but it seems that this is already 
used for "subtitle bitrate"...

Only tested with rawvideo and a transport stream.

Please review, Carl Eugen
-------------- next part --------------
diff --git a/ffmpeg.h b/ffmpeg.h
index e981a74..c03f325 100644
--- a/ffmpeg.h
+++ b/ffmpeg.h
@@ -169,6 +169,8 @@ typedef struct OptionsContext {
     int        nb_pass;
     SpecifierOpt *passlogfiles;
     int        nb_passlogfiles;
+    SpecifierOpt *skip_initial_bytes;
+    int        nb_skip_initial_bytes;
 } OptionsContext;
 
 typedef struct InputFilter {
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 0baa3b1..98fe923 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -775,6 +775,10 @@ static int opt_input_file(void *optctx, const char *opt, const char *filename)
     ic->flags |= AVFMT_FLAG_NONBLOCK;
     ic->interrupt_callback = int_cb;
 
+    if (o->nb_skip_initial_bytes)
+        av_dict_set(&format_opts, "skip_initial_bytes",
+                    o->skip_initial_bytes[o->nb_skip_initial_bytes - 1].u.str, 0);
+
     /* open the input file with generic avformat function */
     err = avformat_open_input(&ic, filename, file_iformat, &format_opts);
     if (err < 0) {
@@ -2369,6 +2373,8 @@ const OptionDef options[] = {
         "extract an attachment into a file", "filename" },
     { "debug_ts",       OPT_BOOL | OPT_EXPERT,                       { &debug_ts },
         "print timestamp debugging info" },
+    { "skip_initial_bytes", HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC, { .off = OFFSET(skip_initial_bytes)},
+        "skip initial bytes", "bytes" },
 
     /* video options */
     { "vframes",      OPT_VIDEO | HAS_ARG  | OPT_PERFILE,                        { .func_arg = opt_video_frames },
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 8f18604..85f052e 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1162,6 +1162,13 @@ typedef struct AVFormatContext {
      */
     enum AVDurationEstimationMethod duration_estimation_method;
 
+    /**
+     * Skip initial bytes when opening stream
+     * - encoding: unused
+     * - decoding: Set by user via AVOptions (NO direct access)
+     */
+    unsigned int skip_initial_bytes;
+
     /*****************************************************************
      * All fields below this line are not part of the public API. They
      * may not be used outside of libavformat and can be changed and
diff --git a/libavformat/options_table.h b/libavformat/options_table.h
index 778c740..3394706 100644
--- a/libavformat/options_table.h
+++ b/libavformat/options_table.h
@@ -72,6 +72,7 @@ static const AVOption options[]={
 {"aggressive", "consider things that a sane encoder shouldnt do as an error", 0, AV_OPT_TYPE_CONST, {.i64 = AV_EF_AGGRESSIVE }, INT_MIN, INT_MAX, D, "err_detect"},
 {"use_wallclock_as_timestamps", "use wallclock as timestamps", OFFSET(use_wallclock_as_timestamps), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX-1, D},
 {"avoid_negative_ts", "avoid negative timestamps", OFFSET(avoid_negative_ts), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, E},
+{"skip_initial_bytes", "skip initial bytes", OFFSET(skip_initial_bytes), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX-1, D},
 {NULL},
 };
 
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 4072ac8..e68e770 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -561,6 +561,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma
 
     if ((ret = init_input(s, filename, &tmp)) < 0)
         goto fail;
+    avio_skip(s->pb, s->skip_initial_bytes);
 
     /* check filename in case an image number is expected */
     if (s->iformat->flags & AVFMT_NEEDNUMBER) {


More information about the ffmpeg-devel mailing list