[FFmpeg-devel] [RFC] Sending H.264 stream to multiple containers

Stefano Sabatini stefasab at gmail.com
Sun Jul 14 18:30:55 CEST 2013


Hi,

My objective is to encode an H.264 stream once and mux it to MP4 and
MPEG-TS at the same time.

This is related to extradata and to how libavcodec stores the data in
the packets. Since there are basically two bitstream formats for
H.264, I'm supposing that libavcodec/libx264 chooses the one depending
on the +global_header flag.

Read for some background:
http://aviadr1.blogspot.it/2010/05/h264-extradata-partially-explained-for.html

For example the following command:
ffmpeg -i slow.flv -map 0 -flags -global_header -c:v libx264  -c:a libvo_aacenc out.mp4

generates an MP4 which can be read by FFmpeg based software, but is
not playable by compliant MP4 equipment, for example:

$ MP4Box -info out.mp4
[iso file] Box "avcC" size 8 invalid (read 34915)
* Movie Info *
	Timescale 1000 - Duration 00:03:58.258
	2 track(s)
	Fragmented File: no
	File Brand isom - version 512
	Created: UNKNOWN DATE
File has no MPEG4 IOD/OD

iTunes Info:
	Encoder Software: Lavf55.12.102

Track # 1 Info - TrackID 1 - TimeScale 30000 - Media Duration 00:03:57.670
Track has 1 edit lists: track duration is 00:03:57.671
Media Info: Language "Undetermined" - Type "vide:avc1" - 7123 samples
Visual Track layout: x=0 y=0 width=320 height=240
MPEG-4 Config: Visual Stream - ObjectTypeIndication 0x21
AVC/H264 Video - Visual Size 320 x 240
	AVC Info: 20 SPS - 0 PPS - Profile Unknown @ Level 2.4
	NAL Unit length bits: 32
[...]

then MP4Box crashes.

Remuxing the file:
ffmpeg -i out.mp4 -c copy out2.mp4
makes the file compliant.

My naive intuition is that if I force global header the encoder should
generate the same bitstream used for MP4 output, and thus should be
convertible to Annex-B format by using the h264_mp4toannexb filter:
ffmpeg -i INPUT -map 0 -flags:v +global_header -c:v libx264 -flags:a +global_header -c:a libvo_aacenc -bsf:v h264_mp4toannexb -y out.ts

unfortunately this command fails on the bitstream filter in the check:
extradata + 2 + unit_size > avctx->extradata + avctx->extradata_size
(see also attached patch for a somehow more useful feedback).

Any idea why this is failing?

...

My objective is to be able to generate a command like this one
(requires my pending and unreviewed -tee_bsfs patch):
ffmpeg -i INPUT -map 0 -flags +global_header -c:v libx264 -c:a libvo_aacenc -tee_bsfs "h264_mp4toannexb:v|aac_adtstoasc:a" -f tee "out.ts|out.mp4"

and avoid the need to remux the generated MP4.

Do you know if this is possible? Do you have specific hints?
-- 
FFmpeg = Fascinating & Frightening Mystic Picky Ephemeral Geek
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-lavc-h264_mp4toannexb-improve-feedback-in-case-of-in.patch
Type: text/x-diff
Size: 1369 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130714/56b42dc7/attachment.bin>


More information about the ffmpeg-devel mailing list