On Sat, 7 Mar 2015, Martin Storsjö wrote:
---
libavformat/movenc.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 122bc2d..67c7214 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -2490,7 +2490,8 @@ static int mov_write_trun_tag(AVIOContext *pb,
MOVMuxContext *mov,
if (i > 0 && get_sample_flags(track, &track->cluster[i]) !=
track->default_sample_flags)
flags |= MOV_TRUN_SAMPLE_FLAGS;
}
- if (!(flags & MOV_TRUN_SAMPLE_FLAGS))
+ if (!(flags & MOV_TRUN_SAMPLE_FLAGS) && track->entry > 0 &&
+ get_sample_flags(track, &track->cluster[0]) !=
track->default_sample_flags)
flags |= MOV_TRUN_FIRST_SAMPLE_FLAGS;
if (track->flags & MOV_TRACK_CTTS)
flags |= MOV_TRUN_SAMPLE_CTS;
--
1.9.3 (Apple Git-50)
This should also be a pretty straightforward patch, potentially saving
some bytes per fragment.
Background for people unfamiliar with this format: The "flags" field
contains flags based on the keyframe flag, different flags for audio and
video samples. The tfhd atom contains one "default" value. If all samples
have the same flags, they don't need to be written out explicitly per
sample, if the default value is the right one. (Patch 1/4 sets this
default to a smarter value.) If the first sample has got different flags
than the rest (but all the other ones have the default flags), we can set
that one separately. And if all samples really have the same flags, we
don't need to set the first sample flags separately either.
E.g., a video fragment where the first sample is a keyframe, and the rest
are P-frames:
tfhd: default = non-sync sample
trun: separate flags for first sample
flags for first sample = sync sample
Audio fragment, keyframe flag set on all samples:
tfhd: default = sync sample
trun: no extra flags for first sample
Prior to patch 1/4, if one muxes audio packets without the keyframe flag
set, it'd look like this:
tfhd: default = sync sample
trun: flags per sample
sample 1: non-sync
sample 2: non-sync
... sample N: non-sync
After patch 1/4, this instead would be:
tfhd: default = non-sync
trun: separate flags for first sample
first sample flags = non-sync
After patch 2/4, this would be:
tfhd: default = non-sync
trun: no flags per packet, no separate flags for first packet
// Martin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel