[FFmpeg-devel] [PATCH] astenc: Add an option to set the loop flag

James Almer jamrial at gmail.com
Sun Dec 23 23:04:29 CET 2012


On 22/12/12 9:10 PM, James Almer wrote:
> ./ffmpeg -help muxer=NAME is enough to get the list of AVOptions of a given muxer. No need to check the entire documentation.
> 
> Here's an updated patch. Using "loop 1" and/or providing a value for loopstart/loopend will enable the flag.
> 
> Regards.

On second thought, since we're not going to use a flag AVOption I'll go with Hoyo's suggestion.
Adding a new integer AVOption for this doesn't make sense.

Regards.

-------------- next part --------------
>From c50187a6055d4da9d037de233977771098ec4f30 Mon Sep 17 00:00:00 2001
From: James Almer <jamrial at gmail.com>
Date: Sun, 23 Dec 2012 18:51:27 -0300
Subject: [PATCH] astenc: Enable the loop flag only when needed


Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavformat/astenc.c  | 36 ++++++++++++++++++++++++------------
 libavformat/version.h |  2 +-
 2 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/libavformat/astenc.c b/libavformat/astenc.c
index 10001c7..d0dc0a8 100644
--- a/libavformat/astenc.c
+++ b/libavformat/astenc.c
@@ -36,7 +36,7 @@ typedef struct ASTMuxContext {
 } ASTMuxContext;
 
 #define CHECK_LOOP(type) \
-    if (ast->loop ## type) { \
+    if (ast->loop ## type > 0) { \
         ast->loop ## type = av_rescale_rnd(ast->loop ## type, enc->sample_rate, 1000, AV_ROUND_DOWN); \
         if (ast->loop ## type < 0 || ast->loop ## type > UINT_MAX) { \
             av_log(s, AV_LOG_ERROR, "Invalid loop" #type " value\n"); \
@@ -69,7 +69,7 @@ static int ast_write_header(AVFormatContext *s)
         return AVERROR(EINVAL);
     }
 
-    if (ast->loopstart && ast->loopend && ast->loopstart >= ast->loopend) {
+    if (ast->loopend > 0 && ast->loopstart >= ast->loopend) {
         av_log(s, AV_LOG_ERROR, "loopend can't be less or equal to loopstart\n");
         return AVERROR(EINVAL);
     }
@@ -85,7 +85,7 @@ static int ast_write_header(AVFormatContext *s)
     avio_wb16(pb, codec_tag);
     avio_wb16(pb, 16); /* Bit depth */
     avio_wb16(pb, enc->channels);
-    avio_wb16(pb, 0xFFFF);
+    avio_wb16(pb, 0); /* Loop flag */
     avio_wb32(pb, enc->sample_rate);
 
     ast->samples = avio_tell(pb);
@@ -140,23 +140,23 @@ static int ast_write_trailer(AVFormatContext *s)
     av_log(s, AV_LOG_DEBUG, "total samples: %"PRId64"\n", samples);
 
     if (s->pb->seekable) {
-        /* File size minus header */
-        avio_seek(pb, ast->size, SEEK_SET);
-        avio_wb32(pb, file_size - 64);
-
         /* Number of samples */
         avio_seek(pb, ast->samples, SEEK_SET);
         avio_wb32(pb, samples);
 
         /* Loopstart if provided */
-        if (ast->loopstart && ast->loopstart >= samples) {
+        if (ast->loopstart > 0) {
+        if (ast->loopstart >= samples) {
             av_log(s, AV_LOG_WARNING, "Loopstart value is out of range and will be ignored\n");
-            ast->loopstart = 0;
-        }
+            ast->loopstart = -1;
+            avio_skip(pb, 4);
+        } else
         avio_wb32(pb, ast->loopstart);
+        } else
+            avio_skip(pb, 4);
 
         /* Loopend if provided. Otherwise number of samples again */
-        if (ast->loopend) {
+        if (ast->loopend && ast->loopstart >= 0) {
             if (ast->loopend > samples) {
                 av_log(s, AV_LOG_WARNING, "Loopend value is out of range and will be ignored\n");
                 ast->loopend = samples;
@@ -168,6 +168,18 @@ static int ast_write_trailer(AVFormatContext *s)
 
         /* Size of first block */
         avio_wb32(pb, ast->fbs);
+
+        /* File size minus header */
+        avio_seek(pb, ast->size, SEEK_SET);
+        avio_wb32(pb, file_size - 64);
+
+        /* Loop flag */
+        if (ast->loopstart >= 0) {
+            avio_skip(pb, 6);
+            avio_wb16(pb, 0xFFFF);
+        }
+
+        avio_seek(pb, file_size, SEEK_END);
         avio_flush(pb);
     }
     return 0;
@@ -175,7 +187,7 @@ static int ast_write_trailer(AVFormatContext *s)
 
 #define OFFSET(obj) offsetof(ASTMuxContext, obj)
 static const AVOption options[] = {
-  { "loopstart", "Loopstart position in milliseconds.", OFFSET(loopstart), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
+  { "loopstart", "Loopstart position in milliseconds.", OFFSET(loopstart), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
   { "loopend",   "Loopend position in milliseconds.",   OFFSET(loopend),   AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
   { NULL },
 };
diff --git a/libavformat/version.h b/libavformat/version.h
index bd14e56..9ad8aa4 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -31,7 +31,7 @@
 
 #define LIBAVFORMAT_VERSION_MAJOR 54
 #define LIBAVFORMAT_VERSION_MINOR 50
-#define LIBAVFORMAT_VERSION_MICRO 102
+#define LIBAVFORMAT_VERSION_MICRO 103
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \
-- 
1.8.0.msysgit.0



More information about the ffmpeg-devel mailing list