[FFmpeg-devel] [PATCH] lavf: split packets before muxing.

Clément Bœsch ubitux at gmail.com
Thu Dec 6 13:47:22 CET 2012


On Mon, Dec 03, 2012 at 11:15:40PM +0100, Clément Bœsch wrote:
> After demuxing, data and side are merged. Before decoding, they are
> split. Encoder will perform with data and side split. This means that a
> muxer can receive split data (after encoding) but also merged data (if
> called directly after demuxing). This commit makes sure data and side
> are split for the muxer.
> ---
>  libavformat/mux.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 

New version merging the side data back after muxing.

[...]

-- 
Clément B.
-------------- next part --------------
From 0727678cbf83be7b7dcb871c8d565b471582103c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= <ubitux at gmail.com>
Date: Mon, 3 Dec 2012 23:13:53 +0100
Subject: [PATCH] lavf: split packets before muxing.

After demuxing, data and side are merged. Before decoding, they are
split. Encoder will perform with data and side split. This means that a
muxer can receive split data (after encoding) but also merged data (if
called directly after demuxing). This commit makes sure data and side
are split for the muxer.
---
 libavformat/mux.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/libavformat/mux.c b/libavformat/mux.c
index 9bcee99..7041bb3a 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -484,13 +484,24 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt)
     return 0;
 }
 
+static inline int split_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+    int ret, did_split;
+
+    did_split = av_packet_split_side_data(pkt);
+    ret = s->oformat->write_packet(s, pkt);
+    if (did_split)
+        av_packet_merge_side_data(pkt);
+    return ret;
+}
+
 int av_write_frame(AVFormatContext *s, AVPacket *pkt)
 {
     int ret;
 
     if (!pkt) {
         if (s->oformat->flags & AVFMT_ALLOW_FLUSH) {
-            ret = s->oformat->write_packet(s, pkt);
+            ret = s->oformat->write_packet(s, NULL);
             if (ret >= 0 && s->pb && s->pb->error < 0)
                 ret = s->pb->error;
             return ret;
@@ -503,7 +514,7 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt)
     if (ret < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
         return ret;
 
-    ret = s->oformat->write_packet(s, pkt);
+    ret = split_write_packet(s, pkt);
     if (ret >= 0 && s->pb && s->pb->error < 0)
         ret = s->pb->error;
 
@@ -733,7 +744,7 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
         if (ret <= 0) //FIXME cleanup needed for ret<0 ?
             return ret;
 
-        ret = s->oformat->write_packet(s, &opkt);
+        ret = split_write_packet(s, &opkt);
         if (ret >= 0)
             s->streams[opkt.stream_index]->nb_frames++;
 
@@ -759,7 +770,7 @@ int av_write_trailer(AVFormatContext *s)
         if (!ret)
             break;
 
-        ret = s->oformat->write_packet(s, &pkt);
+        ret = split_write_packet(s, &pkt);
         if (ret >= 0)
             s->streams[pkt.stream_index]->nb_frames++;
 
-- 
1.8.0.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121206/fc5dc3e0/attachment.asc>


More information about the ffmpeg-devel mailing list