Streampunk / beamcoder

Node.js native bindings to FFmpeg.
GNU General Public License v3.0
393 stars 76 forks source link

Mp4 muxer broken - missing h264 extradata (AVCC) #35

Open jpietek opened 4 years ago

jpietek commented 4 years ago

I'm struggling to get the mp4 muxer output working on Windows10 default video stack, thus Adobe Premiere project bin (on third party players like VLC or Chrome it's playable). The video stream is not recognized at all, no metadata, nothing. Audio is fine.

The muxer is set up similarly as in the mp4 example:

        let vstr = this.mux.newStream({
            name: 'h264',
            encoderName: 'libx264',
            time_base: [1, 90000],
            interleaved: true,
            sample_aspect_ratio: [1, 1],
        });

        Object.assign(vstr.codecpar, {
            width: this.clip.dst_probe.width,
            height: this.clip.dst_probe.height,
            format: 'yuv420p',
            color_space: 'bt709',
            sample_aspect_ratio: [1, 1]
        });

MP4Box -info output, beamcoder muxer:

[iso file] Box "avcC" size 8 invalid (read 17
(...)
Track # 1 Info - TrackID 1 - TimeScale 90000 - Media Duration 00:00:00.840
Track has 2 edit lists: track duration is 00:00:00.920
Media Info: Language "und (und)" - Type "vide:avc1" - 21 samples
Visual Track layout: x=0 y=0 width=1920 height=1080
MPEG-4 Config: Visual Stream - ObjectTypeIndication 0x21
AVC/H264 Video - Visual Size 1920 x 1080
        AVC Info: 1 SPS - 0 PPS - Profile Unknown @ Level 1.6
        NAL Unit length bits: 8
[AVC/HEVC] Not enough bits in bitstream !!
[AVC/HEVC] Not enough bits in bitstream !!
[AVC/HEVC] Not enough bits in bitstream !!
[AVC/HEVC] Not enough bits in bitstream !!
[AVC/HEVC] Not enough bits in bitstream !!
[AVC/HEVC] Not enough bits in bitstream !!
[AVC/HEVC] Not enough bits in bitstream !!
        SPS#1 hash: 2C6E8EB7626F90A283FDE68C6FBE67EE19A48284
Self-synchronized
        RFC6381 Codec Parameters: avc1.000010
        Average GOP length: 21 samples

I've finally figured out that the problem is with missing h264 extradata (AVCC) in stream->codecpar. The source of the video is MPEGTS, which does not provide it (null in js object). I guess the ffmpeg automaticaly adds a proper bitstream filter while transmuxing ts->mp4 (?).

Any idea how to achieve a similar to ffmpeg behaviour with beamcoder? I've tried generating the AVCC bytes on my own, but got it a bit wrong, having some missing frames in the video. Would be easier to get it done with libav itself.

jpietek commented 4 years ago

OK, I'll answer myself in case someone stumbles upon a similar problem. To fix the mp4 just assign in the mp4 muxer: vstr.codecpar.extradata = ts_demux.streams[video_index].codecpar.extradata;

scriptorian commented 4 years ago

Thanks for this. The bitstream filter docs say that for ffmpeg the h264_mp4toannexb filter is auto-inserted for MPEG-TS (muxer mpegts) and raw H.264 (muxer h264) output formats. More to do!