Minimalistic MP4 mux/demux single header library

Overview

Mini MP4

Build Status

Easy embeddable MP4 mux/demux library.

Usage

Muxing

Muxing can be done using 3 modes. Default mode uses one big mdat chunk:

default

This is most efficient mode, but disadvantage is that we need go back and patch mdat chunk size. This can be a problem in some cases, for example if stream transfered over network. To workaround this sequential mode is used:

default

This mode do not make any backwards seek. And last mode is fragmented aka fMP4.

default

This mode stores track information first and spreads indexes across all stream, so decoding can start before whole stream available. This mode is sequential too and usually used by browsers and HLS streaming.

Bindings

Interesting links

Comments
  • Assumes correct SPS/PPS

    Assumes correct SPS/PPS

    for work on Nvidia embedded Jetson solution , i switch off MINIMP4_TRANSCODE_SPS_ID and fix compilation.

    • offset is good on uint64.
    • 40Go / 2hours for a MP4 file but unreadable.

    So, i cant make a readable files with more than 4Go ... Beyond that , in MediaInfo , isTruncated status become TRUE and the file is unreadable into VLC/Mplayer.

    I forgot something in code ?

    opened by Syd76 33
  • x265 with aac to mp4?

    x265 with aac to mp4?

    Is it possible to take h265/x265/hvec file and aac files to make up an mp4? From my understanding the example only puts h264 into mp4 yes? What will it take to make to make the h265 and aac files mux into an mp4 using this library? Most of the muxers don't actually include h265 as a supported format in the muxer, any resources you can point me to on that please. Thank you.

    question 
    opened by adminy 12
  • fragmentation mode doesn't work with audio

    fragmentation mode doesn't work with audio

    Steps to reproduce:

    1. Enable ENABLE_AUDIO in minimp4_test.c. Change resolution to 240x160.
    2. Build minimp4_test with fdk-aac-2.0.1.
    3. Download stream.h264 and stream.pcm from https://github.com/lieff/minirtmp.
    4. Run following tests: ./minimp4_x86 -m stream.h264 stream.mp4 ./minimp4_x86 -m -s stream.h264 stream-s.mp4 ./minimp4_x86 -m -f stream.h264 stream-f.mp4
    5. stream.mp4 and stream-s.mp4 are playable with audio. stream-f.mp4 is not playable.

    Can you help to take a look? Thanks! stream-f.mp4.zip

    opened by rhwu 11
  • mux h265 stream cannot play

    mux h265 stream cannot play

    i mux .265 file to an mp4 file ffmpeg cannot parse it

    cl minimp4_test.c
    ffmpeg -i 1.jpg 1.265
    minimp4_test.exe 1.265 1.mp4
    ffmpeg -i 1.mp4
    

    export:

    [AVBSFContext @ 0000016c771221c0] No start code is found.
    1.mp4: could not find codec parameters
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '1.mp4':
      Metadata:
        major_brand     : mp42
        minor_version   : 0
        compatible_brands: mp42isom
      Duration: 00:00:00.03, bitrate: N/A
        Stream #0:0(und): Video: hevc (hvc1 / 0x31637668), none, 352x288, 56174 kb/s, 30 fps, 30 tbr, 90k tbn (default)
        Metadata:
          handler_name    : VideoHandler
    

    image

    enhancement 
    opened by darkskygit 5
  • add optional TFDT support

    add optional TFDT support

    Optionally Add TFDT to TRAF, so that the resulting fMP4 is compatible with https://www.w3.org/TR/mse-byte-stream-format-isobmff/ and can be played from a SourceBuffer in MediaSource.

    The change is made to change nothing by default, and be enabled with a simple flag.

    Resulting fMP4 played successfully with MediaSource on:

    • Safari
    • Firefox
    • Chrome
    • Edge
    opened by blld 4
  • Access Unit Delimiter (AUD) handling

    Access Unit Delimiter (AUD) handling

    I'm using this library to mux a H.264 bitstream that contains type 9 NAL units (Access unit delimiter) before each full frame.

    According to Wikipedia, the Unit Access Delimiter is used as a basic prefix NAL unit to aid in interpreting frames:

    A set of NAL units in a specified form is referred to as an access unit. The decoding of each access unit results in one decoded picture. Each access unit contains a set of VCL NAL units that together compose a primary coded picture. It may also be prefixed with an access unit delimiter to aid in locating the start of the access unit.

    The code on master will return an error if it encounters an AUD, whereas it seems to work fine by skipping over the NAL unit. I think this is because it's an optional 'helper' unit that the library does not depend on to correctly interpret the stream.

    The code I've experimented with essentially changes a return err statement to instead continue parsing other NAL units in the buffer:

    2343| if (9 == payload_type)
    2344|     return err; /* access unit delimiter */
    
    2343| if (9 == payload_type)
    2344|     continue; /* access unit delimiter */
    

    It would be nice not to have to maintain a long lived fork, so I'm submitting this as a way of opening discussion to solutions for handling such streams (as are produced by the built-in Windows H.264 Encoder). More than happy to contribute code.

    opened by b71729 3
  • When each i/IDR frame has SPS/PPS will be crash.

    When each i/IDR frame has SPS/PPS will be crash.

    static int transcode_nalu(h264_sps_id_patcher_t* h, const unsigned char* src, int nalu_bytes, unsigned char* dst)
    {
        int old_id;
    
        ......
    
        switch (payload_type)
        {
        .......
        case 8:
        {
            int cb = patch_pps(h, bst, bdt, 0, &old_id);
            int id = find_mem_cache(h->pps_cache, h->pps_bytes, MINIMP4_MAX_PPS, dst + 1, cb);
            if (id == -1)
                return 0;
            h->map_pps[old_id] = id;
            patch_pps(h, bs, bd, id, &old_id);
        }
        ......
    }
    
        typedef struct
        {
            .......
            int map_sps[MINIMP4_MAX_SPS]; // MINIMP4_MAX_SPS equal to 32
            int map_pps[MINIMP4_MAX_SPS];
    
        } h264_sps_id_patcher_t;
    

    Access to array 'pps' overflow cause by variable 'old_id' can be greater than 32.

    opened by pfreedev 3
  • all modes failed on certain bitstream

    all modes failed on certain bitstream

    Attached test2.264 (640x480) failed on all the 3 modes. But I'm able to do muxing with this bitstream using ffmpeg: $ ffmpeg -framerate 30 -i test2.264 -c copy test2.mp4

    test2.264.zip

    opened by rhwu 2
  • can this lib use for fmp4 push to browser  mse api sourceBuffer?

    can this lib use for fmp4 push to browser mse api sourceBuffer?

    hi, this is great job. thanks for your code. I want to use this library to play annexb video streams in edge or chrome browser using mediaSource API. can you help me some usecase ,such as file output convert to stream buffer output.

    opened by xiangxud 1
  • Cmd line bug, typos.

    Cmd line bug, typos.

    -    int is_hevc = (0 != strstr(argv[1], "265")) || (0 != strstr(argv[i], "hevc"));
    +    int is_hevc = (0 != strstr(argv[i], "265")) || (0 != strstr(argv[i], "hevc"));
    

    // Second is optonal duration update at beginning of file in fragmenatation mode. ===> Proofread.

    Thanks for the project.

    opened by seerdecker 1
  • Replace search for zero byte with memchr()

    Replace search for zero byte with memchr()

    While profiling minimp4 during MP4 encoding, find_start_code showed up as the most expensive function. Specifically, the first while loop searching for an initial zero byte. This is effectively what memchr() does, and glibc includes an optimized version of this method. Switching to memchr() showed a performance improvement in this method.

    opened by jhurliman 1
  • H265 to mp4 half video is gray image

    H265 to mp4 half video is gray image

    when i am trying to convert H265 file to mp4 file i am seeing half image as gray in entire video. Please sagest what changes i need to do to solve this issue its not working for any mode and when i am converting it from ffmpeg its working fine. please help me.

    opened by yp13 0
  • Add an SLConfigDescriptor to the ES_Descriptor

    Add an SLConfigDescriptor to the ES_Descriptor

    Should fix issue #25 - I'm not sure where in the spec this is defined, but I've found references that state in MP4 files, the SLConfigDescriptor is required, and needs to be set to 2, see http://gpac.sourceforge.net/tutorial/bifs_part3.htm

    opened by jprjr 0
  • Add methods for manual flushing and changing write offset

    Add methods for manual flushing and changing write offset

    Use case - generating fragmented MP4s for HLS streaming requires creating an initialization segment with decoder-specific config (the moov box). Manual flush allows writing out the moov box before adding samples.

    Similar with write offset - after writing the moov box, one wants to write media segments that begin with a moof box and have 1 or more mdat boxes. This adds a method for overwriting the write offset, in case the library user wants to treat MP4E_mux_t as an opaque type.

    opened by jprjr 1
  • Add function to find sync frames and store avc1 codec information

    Add function to find sync frames and store avc1 codec information

    These are actually 3 commits. The first fixes warnings (mainly signedness comparisons and unused stuff). The second adds MP4D_nearest_sync_frame which lets you find the nearest key/sync frame given any frame in the video stream. This is useful when implementing random access functionality and you want to start on a key frame. The third commit stores avc1 codec information. The WebCodecs API requires a valid codec string. To build this string you need the three bytes from the AVCDecoderConfigurationRecord. Maybe in the future we could also add a function to generate this string. :)

    Please let me know if this ok or I should submit separate PRs.

    opened by fabioarnold 0
  • Crash when parsing malformed 264 files

    Crash when parsing malformed 264 files

    Hi folks,

    An interesting crash was found while fuzz testing of the minimp4_x86 binary which can be triggered via a malformed 264 file. Although this malformed file only crashes the program as-is, it could potentially be crafted further and create a security issue where these kinds of files would be able compromise the process's memory through taking advantage of affordances given by memory corruption. It's recommend to harden the code to prevent these kinds of bugs as it could greatly mitigate such this issue and even future bugs.

    Repro crash.264.txt

    $ minimp4_x86 crash.264 test.mp4
    Segmentation fault (core dumped)
    
    $ gdb -q minimp4_x86
    Reading symbols from minimp4_x86...
    (No debugging symbols found in minimp4_x86)
    
    (gdb) r crash.264 test.mp4
    Starting program: minimp4_x86 crash.264 test.mp4
    
    Program received signal SIGBUS, Bus error.
    0x0000555555558cac in patch_pps ()
    
    (gdb) bt
    #0  0x0000555555558cac in patch_pps ()
    #1  0x0000555555555dd1 in main ()
    
    (gdb) i r
    rax            0x6510              25872
    rbx            0x7fffffffcf70      140737488342896
    rcx            0xfffffff8          4294967288
    rdx            0xc204e00           203443712
    rsi            0x1                 1
    rdi            0x7fffffffcfb0      140737488342960
    rbp            0x7fffffffd040      0x7fffffffd040
    rsp            0x7fffffffcec8      0x7fffffffcec8
    r8             0x2511              9489
    r9             0x555555563679      93824992294521
    r10            0x1                 1
    r11            0x0                 0
    r12            0x7fffffffcf6c      140737488342892
    r13            0x37                55
    r14            0x1926              6438
    r15            0x555555563670      93824992294512
    rip            0x555555558cac      0x555555558cac <patch_pps+44>
    eflags         0x10206             [ PF IF RF ]
    cs             0x33                51
    ss             0x2b                43
    ds             0x0                 0
    es             0x0                 0
    fs             0x0                 0
    gs             0x0                 0
    
    (gdb) x/i $rip
    => 0x555555558cac <patch_pps+44>:	mov    0xd80(%rbp,%rax,4),%r8d
    
    (gdb) exploitable
    Description: Access violation
    Short description: AccessViolation (21/22)
    Hash: 7bfba3fa9abe7b60a7e8004b251c9358.7bfba3fa9abe7b60a7e8004b251c9358
    Exploitability Classification: UNKNOWN
    Explanation: The target crashed due to an access violation but there is not enough additional information available to determine exploitability.
    
    opened by retpoline 0
  • Cannot demux MP4 files in H265 format

    Cannot demux MP4 files in H265 format

    Hi, lieff: I want to demux MP4 files in H265 compressed format, but I found that it doesn't work, even though the MP4 files I use are generated by itself. I tracked it down and found that after opening the file with MP4D_open, the dsi information is empty. Can you provide some advice, thanks very much.

    opened by huangzhiyou-github 2
Owner
Lion
mov ax,0013h int 10h
Lion
The Dolby MP4 streaming demuxer (dlb_mp4demux) is a software implementation of a demuxer of fragmented or unfragmented ISO base media file format (mp4).

The Dolby MP4 streaming demuxer (dlb_mp4demux) is a software implementation of a demuxer of fragmented or unfragmented ISO base media file format (mp4). It supports demuxing of Dolby Digital (AC-3), Dolby Digital Plus (E-AC-3), and Dolby AC-4 audio formats as well as Dolby Vision. It is designed for use on architectures with limited resources.

Dolby Laboratories 63 Jul 9, 2022
Minimalistic MP3 decoder single header library

minimp3 Minimalistic, single-header library for decoding MP3. minimp3 is designed to be small, fast (with SSE and NEON support), and accurate (ISO con

Lion 1.2k Sep 18, 2022
Single file audio playback and capture library written in C.

A single file library for audio playback and capture. Example - Documentation - Supported Platforms - Backends - Major Features - Building - Unofficia

David Reid 2.4k Sep 21, 2022
Single file C library for decoding MPEG1 Video and MP2 Audio

PL_MPEG - MPEG1 Video decoder, MP2 Audio decoder, MPEG-PS demuxer Single-file MIT licensed library for C/C++ See pl_mpeg.h for the documentation. Why?

Dominic Szablewski 577 Sep 21, 2022
Single file synth + demo song

P.S. is a music track written from scratch using the C programming language. All sounds and notes were entered manually without using any music progra

NightRadio 43 Aug 14, 2022
A tiny, header only, easy to use, cross-platform, portaudio wrapper, sound and notation manager, tailored for the demo scene.

TDAW A tiny, header only, easy to use, cross-platform, portaudio wrapper, sound and notation manager, tailored for the demo scene. This header enables

kbx 12 Sep 17, 2022
A simple C++ library for reading and writing audio files.

AudioFile A simple header-only C++ library for reading and writing audio files. Current supported formats: WAV AIFF Author AudioFile is written and ma

Adam Stark 644 Sep 16, 2022
A C library for reading and writing sound files containing sampled audio data.

libsndfile libsndfile is a C library for reading and writing files containing sampled audio data. Authors The libsndfile project was originally develo

null 1k Sep 15, 2022
C library for cross-platform real-time audio input and output

libsoundio C library providing cross-platform audio input and output. The API is suitable for real-time software such as digital audio workstations as

Andrew Kelley 1.6k Sep 19, 2022
C++ Audio and Music DSP Library

_____ _____ ___ __ _ _____ __ __ __ ____ ____ / \\_ \\ \/ / |/ \| | | | \_ \/ \ | Y Y \/ /_ \> <| | Y Y \ | |_|

Mick Grierson 1.3k Sep 24, 2022
🎵 Music notation engraving library for MEI with MusicXML and Humdrum support and various toolkits (JavaScript, Python)

Verovio is a fast, portable and lightweight library for engraving Music Encoding Initiative (MEI) digital scores into SVG images. Verovio also contain

RISM Switzerland 499 Sep 26, 2022
highly efficient sound library for the Gameboy Advance

The Apex Audio System (AAS) is a sound library for the GBA. It includes a highly efficient mixer, MOD playing routines and support for up to 16 channels. It is designed for developers using a GCC-based development environment. AAS uses RAW, WAV or *tracker 1-16 channel MOD files as input.

Ties Stuij 31 Jul 15, 2022
A lightweight music DSP library.

Soundpipe Soundpipe is a lightweight music DSP library written in C. It aims to provide a set of high-quality DSP modules for composers, sound designe

Paul Batchelor 102 Dec 14, 2021
PortAudio is a portable audio I/O library designed for cross-platform support of audio

PortAudio is a cross-platform, open-source C language library for real-time audio input and output.

PortAudio 704 Sep 15, 2022
LibMEI is a C++ library for reading and writing MEI files

C++ library and Python bindings for the Music Encoding Initiative format

Distributed Digital Music Archives and Libraries Lab 53 Aug 31, 2022
C++17 library for creating macOS Audio Server plugins.

libASPL Synopsis Instructions Versioning API reference Example driver Quick start Object model Types of setters Customization Thread and realtime safe

Victor Gaydov 27 Aug 21, 2022
lua-nuspell is a set of Lua 5.x bindings for Nuspell spellchecking C++ library.

lua-nuspell lua-nuspell is a set of Lua 5.x bindings for Nuspell spellchecking C++ library. About Nuspell Nuspell is a fast and safe spelling checker

AF 7 Jul 3, 2022
a library for audio and music analysis

aubio is a library to label music and sounds. It listens to audio signals and attempts to detect events. For instance, when a drum is hit, at which frequency is a note, or at what tempo is a rhythmic melody.

aubio 2.8k Sep 21, 2022
Cross-platform silk codec wrap library depends on ploverlake/silk.

libSilkCodec Cross-platform silk codec wrap library depends on ploverlake/silk. Clone & Build Linux/Unix like # clone $ git clone https://github.c

KonataDev 8 Sep 9, 2022