Content
Getting General Info on mp4-file
Encapsulation h264 elementary stream into mp4 format
Concatenation of mp4 files into new mp4-file
Getting MP4Box Binaries
MP4Box tool is an alternative to ffmpeg (for mp4 issues), and it’s a part of GPAC package.
For Windows:
Windows version of MP4Box.exe can be downloaded via over-advertised site https://softradar.com/mp4box/download/ , actually you need to extract mp4box.exe and two dll-files: msvcr100.dll and js32.dll.
Alternatively you can download the latest version of GPAC from https://gpac.wp.imt.fr/downloads/gpac-nightly-builds/ , this package contains MP4Box inside, you need check MP4Box to get MP4Box.exe only
mp4box.exe will be located at C:\Program Files\GPAC and the path environment is updated respectively.
For Linux:
sudo apt-get install gpac
Commands
Getting General Info on mp4-file
the switch ‘-info’ provides general info and info for each track:
mp4box -info Test_720x576_1200kbps.mp4
* Movie Info *
Timescale 1000 – Duration 00:01:53.082
Fragmented File no – 2 track(s)
File Brand isom – version 512
Created: UNKNOWN DATE
File has no MPEG4 IOD/OD
iTunes Info:
Encoder Software: Lavf58.35.100
Track # 1 Info – TrackID 1 – TimeScale 30000 – Duration 00:01:53.046
Media Info: Language “Undetermined” – Type “vide:avc1” – 3388 samples
Visual Track layout: x=0 y=0 width=720 height=576
MPEG-4 Config: Visual Stream – ObjectTypeIndication 0x21
AVC/H264 Video – Visual Size 720 x 576
AVC Info: 1 SPS – 1 PPS – Profile Baseline @ Level 3.1
NAL Unit length bits: 32
Pixel Aspect Ratio 1:1 – Indicated track size 720 x 576
Self-synchronized
Track # 2 Info – TrackID 2 – TimeScale 44100 – Duration 00:01:53.081
Media Info: Language “Undetermined” – Type “soun:mp4a” – 4870 samples
MPEG-4 Config: Audio Stream – ObjectTypeIndication 0x40
MPEG-4 Audio AAC LC – 2 Channel(s) – SampleRate 44100
Synchronized on stream 1
Alternate Group ID 1
One can see that the track 1 is h264 video (vide:avc1) and the track 2 is audio data (AAC format).
Note: To get metadata related to the track #N use the following command: MP4Box -info N mp4-file
For example in order to get info about track #1:
MP4Box -info 1 output.mp4
Output:
Track # 1 Info - TrackID 1 - TimeScale 25000 - Media Duration 00:04:19.600
Track is present in Root OD
Media Info: Language "Undetermined" - Type "vide:avc1" - 6490 samples
Handler name: ETI ISO Video Media Handler
Visual Track layout: x=0 y=0 width=1280 height=720
MPEG-4 Config
Visual Stream - ObjectTypeIndication 0x21
AVC/H264 Video - Visual Size 1280 x 720
AVC Info: 1 SPS - 1 PPS - Profile High @ Level 3.1
NAL Unit length bits: 32
Pixel Aspect Ratio 1:1 - Indicated track size 1280 x 720
Chroma format 1 - Luma bit depth 8 - chroma bit depth 8
Decoding Buffer size 120906 - Average bitrate 1804 kbps - Max Bitrate 4075 kbps
No stream dependencies for decoding
StreamPriority 0
Computed info from media:
Total size 58561532 bytes - Total samples duration 259560 ms
Average rate 1804 kbps - Max Rate 3608 kbps
Chunk durations: min 40 ms - max 40 ms - average 40 ms
Chunk sizes (bytes): min 183 - max 120906 - average 9023
Encapsulation h264 elementary stream into mp4 format
Encapsulate h264 elementary stream with the frame rate 50fps (if the frame rate is not explicitly mentioned then the default 25 fps is taken):
mp4box -nodrop -add crowdrun1080p.h264:fps=50 -new crowd.mp4
-nodrop force constant FPS when importing video
-new – create a new file
Sometime it’s required to change some parameters in mp4 metadata, e.g. the language or track handler name. For example, to change the language into ‘rus’ (Russian) within mdhd-box and the handler name in hdlr-box use:
mp4box -add test.h264:lang=ru:name=”AVC Shevach Video” -new output.mp4
Concatenation of mp4 files into new mp4-file
the parameter ‘-cat’ should be used two concatenate two mp4-file in a single mp4 file:
mp4box -cat test_001.mp4 -cat test_002.mp4 -new test_12.mp4
In-Place Removal Hint Tracks
If mp4-file contains hint tracks you can remove these tracks in-place by the command ‘-unhint’
mp4box -unhint test.mp4
MPEG-DASH Segmentation
To segment the input mp4 file into fragments of m4s files, where each fragment has duration of 4s (depending on key frames)
mp4box -dash 4000 -frag 4000 -rap -segment-name slava_ input.mp4
-dash 4000 segment into 4000ms chunks
-frag 4000 segments are not fragmented further since the duration coincide
-rap forces segments to start random access points, i.e. keyframes. In such a case segment’s duration may differ from 4000ms depending on distribution of key frames.
-segment-name specifies the pattern of segments names. So in this case, the segments will be named like this: slava_1.m4s, slava_2.m4s, …
How Add Copyright In-Place
There is a special box ‘cprt’ to put the copyright. This box is signaled within ‘udta’ box.
To add a copyright name in-place use ‘-cprt string’:
mp4box -cprt “Shevach Riabtsev” input.mp4
Add Language Tag
Language tags are specified by ISO 639-2. Let’s suppose you need set the language tag English (‘en’ according to ISO 639-2) in audio trak #2 of mp4-file (or mov-file) in-place:
mp4box -lang 2=en test.mp4
To find audio track (handler type ‘soun’) use ffprobe tool, e.g.:
ffprobe -hide_banner -i test_real_clock.mp4 -show_streams
[STREAM]
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
profile=High
codec_type=video
codec_tag_string=avc1
….
[/STREAM]
[STREAM]
index=1
codec_name=mp2
codec_long_name=MP2 (MPEG audio layer 2)
profile=unknown
codec_type=audio
codec_tag_string=mp4a
codec_tag=0x6134706d
sample_fmt=fltp
sample_rate=44100
channels=2
channel_layout=stereo
…
[/STREAM]
The audio track is #2 (counted from 1), let’s add the language tag ‘en’:
mp4box -lang 2=en test_real_clock.mp4
Verification:
ffprobe -hide_banner -i test_real_clock.mp4 -show_streams
…
[STREAM]
index=1
codec_name=mp2
codec_long_name=MP2 (MPEG audio layer 2)
profile=unknown
codec_type=audio
codec_tag_string=mp4a
codec_tag=0x6134706d
sample_fmt=fltp
sample_rate=44100
channels=2
channel_layout=stereo
…
TAG:language=eng
TAG:handler_name=SoundHandler
TAG:vendor_id=[0][0][0][0]
[/STREAM]
Extract Elementary Stream
From ‘mp4box -info mp4-file‘ you know that the track #1 is h264 video then the following command extract the elementary h264 stream from the mp4-file:
MP4Box -raw 1 input.mp4 -out es.h264
Extracting MPEG-4 AVC-H264 stream to h264
Note: if es.h264 exists mp4box does not overwrite it and does not extract data, although a corresponding print is issued. In such case i recommend to use ‘-new’ instead of ‘-out’, you get the error: “Error – 2 input names specified, please check usage”
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
Some genuinely interesting points you have written.Assisted me a lot, just what I was searching for : D.
Hello, i believe that i saw you visited my website so i came to “return the desire”.I am attempting to find issues to improve my site!I suppose its ok to use some of your ideas!!
you are welcome to take anything from my site (even without mentioning me)
You made some clear points there. I did a search on the subject and found most people will consent with your site.
I’m really enjoying the design and layout of your blog. It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a designer to create your theme? Great work!
Regards for this post, I am a big fan of this site would like to continue updated.
I love foregathering useful info, this post has got me even more info! .
Nice post. I learn something more challenging on different blogs everyday. It will always be stimulating to read content from other writers and practice a little something from their store. I’d prefer to use some with the content on my blog whether you don’t mind. Natually I’ll give you a link on your web blog. Thanks for sharing.
Hello my friend! I wish to say that this article is awesome, nice written and come with almost all vital infos. I would like to peer extra posts like this .
After research a number of of the weblog posts in your website now, and I really like your manner of blogging. I bookmarked it to my bookmark website checklist and will likely be checking again soon. Pls take a look at my web site as well and let me know what you think.
I absolutely love your blog and find a lot of your post’s to be exactly I’m looking for. can you offer guest writers to write content for yourself? I wouldn’t mind composing a post or elaborating on a few of the subjects you write in relation to here. Again, awesome web site!
This design is steller! You definitely know how to keep a reader entertained. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Great job. I really loved what you had to say, and more than that, how you presented it. Too cool!
whoah this blog is magnificent i love reading your articles. Keep up the great work! You know, many people are looking around for this information, you could help them greatly.
Hi videonerd.website administrator, Thanks for the well-researched post!
Hi videonerd.website administrator, Your posts are always well structured and easy to follow.
Hello videonerd.website owner, You always provide valuable information.
Hello videonerd.website admin, Keep it up!