Content
Conversion regular mp4-file into the fragmented
Parsing mp4-file metadata with mp4dump
Extract single box from mp4-file with mp4extract
Removal atoms from mp4-file with mp4edit
Encryption: mp4encrypt and mp4decrypt
Representation mp4 metadata tables in more compact form (squeeze)
How Create and Build Bento4 Visual Studio Solution
Download binaries (for all platforms):
https://www.bento4.com/downloads/
Documentation:
i recommend
- the book “Learn to Produce Videos with FFmpeg: In Thirty Minutes or Less“, 2018 Edition, by Jan Ozer , there is a section “Working with Bento4” .
1) Conversion regular mp4-file into the fragmented
Program Mp4fragment.exe from Bento4 packet, this program is tailored to convert regular mp4-file to fragmented one (format of MP4 fragmented files)
fragment input ordinary mp4-file into the fragmented, each fragment is ~1s of duration, by default video and audio are in separated moof-boxes
mp4fragment.exe test .mp4 --fragment-duration 1000 test_f.mp4
Note: If only the video track is supposed to be converted, use ‘–track video’ and the output file will contain only video data.
mp4fragment.exe test .mp4 --track video --fragment-duration 1000 test_f.mp4
There is a free tool to parse mp4-files (including fragmented) Mp4Explorer
2) Parsing mp4-file metadata with mp4dump
Parsing video track (number 1), using verbosity=0 to get only general meta-data for a specific track (track numbering from 1):
mp4dump --verbosity 0 --track 1 crowdrun1080p.mp4
[ftyp] size=8+24
major_brand = isom
minor_version = 200
compatible_brand = isom
compatible_brand = iso2
compatible_brand = avc1
compatible_brand = mp41
[free] size=8+0
[mdat] size=8+43841032
[moov] size=8+5252
[mvhd] size=12+96
timescale = 1000
duration = 20020
duration(ms) = 20020
[trak] size=8+5038
[tkhd] size=12+80, flags=3
enabled = 1
id = 1
duration = 20020
width = 1920.000000
height = 1080.000000
[edts] size=8+28
[elst] size=12+16
entry_count = 1
entry/segment duration = 19980
entry/media time = 48000
entry/media rate = 1
[mdia] size=8+4902
[mdhd] size=12+20
timescale = 1200000
duration = 24024000
duration(ms) = 20020
language = und
[hdlr] size=12+33
handler_type = vide
handler_name = VideoHandler
[minf] size=8+4817
[vmhd] size=12+8, flags=1
graphics_mode = 0
op_color = 0000,0000,0000
[dinf] size=8+28
[dref] size=12+16
[url ] size=12+0, flags=1
location = [local to file]
[stbl] size=8+4753
[stsd] size=12+145
entry_count = 1
[avc1] size=8+133
data_reference_index = 1
width = 1920
height = 1080
compressor =
[avcC] size=8+47
Configuration Version = 1
Profile = High
Profile Compatibility = 0
Level = 42
NALU Length Size = 4
Sequence Parameter = [67 64 00 2a ac d9 40 78 02 27 e5 84 00 00 03 00 04 00 00 03 01 90 3c 60 c6 58]
Picture Parameter = [68 eb e3 cb 22 c0]
[stts] size=12+20
entry_count = 2
[stss] size=12+20
entry_count = 4
[stsc] size=12+304
entry_count = 25
[stsz] size=12+4008
sample_size = 0
sample_count = 1000
[stco] size=12+184
entry_count = 45
[udta] size=8+90
[meta] size=12+78
[hdlr] size=12+21
handler_type = mdir
handler_name =
[ilst] size=8+37
[.too] size=8+29
[data] size=8+21
type = 1
lang = 0
value = Lavf58.49.100
3) Extract single box from mp4-file with mp4extract
Let's suppose we wish to extract ctts-box of video track (which contains presentation times of each sample) and write the whole ctts-atom in a binary file ctts.bin. If video track is the first track in the input mp4-file then the following command can be used: mp4extract moov/trak[0]/mdia/minf/stbl/ctts crowdrun1080p.mp4 ctts.bin Note: ctts -box is not mandatory and it usually is present if B frames are present in video elementary stream. 4) Removal atoms from mp4-file with mp4edit Some boxes (atoms) in mp4 file metadata are not mandatory and can be removed. For example 'udta' box is user-data box and can be discarded. The program mp4edit enables to remove boxes in mp4-file's metadata (bear in mind not to remove mandatory boxes), you need provide a path to the box to be discarded:
mp4edit --remove moov/udta input.mp4 output.mp4
Note: udta-box has been removed but mdat-box and moov-box (meta-data) were unintentionally swapped in places (a side effect).
5) Encryption: mp4encrypt and mp4decrypt
mp4encypt provide the following encryption methods (some requires fragmented mp4):
OMA-PDCF-CBC,
OMA-PDCF-CTR,
MARLIN-IPMP-ACBC,
MARLIN-IPMP-ACGK,
ISMA-IAEC,
PIFF-CBC,
PIFF-CTR,
MPEG-CENC,
MPEG-CBC1,
MPEG-CENS,
MPEG-CBCS
Encryption of mp4-file with the metod OMA-PDCF-CBC ( = AES-CBC with the key 128 bits), the key (16 chars) was randomly chosen, the initialization vector is ‘shevach‘, the track with track_id=1 (video) is encrypted:
mp4encrypt.exe --method OMA-PDCF-CBC --key 1:594b01e0aa0632b0aac7339d3703b2ce:shevach C:\Tools\fifa_wp.mp4 fifa_wp_encr.mp4
Apply mp4info to get information on fifa_wp_encr.mp4
Track 1:
flags: 3 ENABLED IN-MOVIE
id: 1
type: Video
duration: 14200 ms
language: und
media:
sample count: 320
timescale: 90000
duration: 1152000 (media timescale units)
duration: 12800 (ms)
bitrate (computed): 19129.190 Kbps
display width: 1920.000000
display height: 1080.000000
frame rate (computed): 25.000
Sample Description 0
[ENCRYPTED]
Coding: encv
Scheme Type: odkm
Scheme Version: 512
Scheme URI:
odkm Scheme Info:
Selective Encryption: yes
Key Indicator Length: 0
IV Length: 16
Encryption Method: AES-CBC
Content ID:
Rights Issuer URL:
Coding: avc1 (H.264)
Codec String: avc1.640032
AVC Profile: 100 (High)
AVC Profile Compat: 0
AVC Level: 50
AVC NALU Length Size: 4
AVC SPS: [67640032acc4201e0089f96008]
AVC PPS: [68ef38b000]
Width: 1920
Height: 1080
Depth: 24
To decrypt the encrypted file psl. do the following (decrypt only track with track_id=1):
mp4decrypt.exe --key 1:594b01e0aa0632b0aac7339d3703b2ce fifa_wp_encr.mp4 fifa_wp_decrypt.mp4
Representation mp4 metadata tables in more compact form
Most of tables in mp4 metadata can be coded in run-length form. The program mp4compact.exe attempts to represent metadata tables (e.g. ctts – composition times) in more compact form. Thus, the whole mp4-file size is squeezed.
Example [input file contains two tracks: audio (track_id=1) and video (track_id=2), metadata of audio track can be squeezed]
mp4compact.exe --verbose 403.mp4 403_compact.mp4
Track 1: stz2 reduction = 9384 bytes audio track
Track 2: no stz2 reduction possible video track
Total stz2 reduction = 9384 bytes
How Create and Build Bento4 Visual Studio Solution
Bento4 sources are located here, pls. clone them with ‘git clone’. Upon cloning of Bento4 sources go to Build directory and apply the following code to create Visual Studio solution bento4.sln:
cmake .. -G “Visual Studio 16 2019” -DCMAKE_GENERATOR_PLATFORM=x64 -DBUILD_TESTING=OFF
Apply ‘All_Build’ and the following binaries are created at Bento4\Build\Release
aac2mp4.exe
avcinfo.exe
fixaacsampledescription.exe
hevcinfo.exe
mp42aac.exe
mp42avc.exe
mp42hevc.exe
mp42hls.exe
mp42ts.exe
mp4audioclip.exe
mp4compact.exe
mp4dcfpackager.exe
mp4decrypt.exe
mp4diff.exe
mp4dump.exe
mp4edit.exe
mp4encrypt.exe
mp4extract.exe
mp4fragment.exe
mp4iframeindex.exe
mp4info.exe
mp4mux.exe
mp4pssh.exe
mp4rtphintinfo.exe
mp4split.exe
mp4tag.exe
23+ years’ programming and theoretical experience in the computer science fields such as video compression, media streaming and artificial intelligence (co-author of several papers and patents).
the author is looking for new job, my resume
Very nice write-up. I definitely appreciate this website.
Keep it up!