Create different qaulities for my manifest with only mp4box - ffmpeg

I asked a question on slack on why the quality and bitrate of my dash video wasn't changing and I got this response: You only have one quality in your manifest. there is no way for the player to choose a different one
So how can I create different "qualities"?
I have a mp4box command like:
MP4Box -dash 2000 -profile dashavc264:live -bs-switching multi -url-template whatever.mp4#trackID=1:id=vid0:role=vid0 whatever.mp4#trackID=2:id=aud0:role=aud0 -out whatever.mpd
Would it be possible to create different "qualities" with only mp4box or would I have to create the same video with different resolutions with something like ffmpeg and then feed them into the inputs to the command above?

GPAC contributor here. Since v0.9, GPAC has introduced a new architecture that allows to transcode by leveraging FFmpeg.
Example (forced intra period of 2 seconds):
MP4Box -dash 2000 -profile dashavc264:live -out session.mpd source.mp4:##enc:c=avc:fintra=2
Edit: since 2020/09/29 multi-encoding is possible
MP4Box -fgraph -dash 2000 -profile dashavc264:live source.mp4:#ffsws:osize=160x120#enc:c=avc:fintra=2:b=100k:#Representation=1##ffsws:osize=320x240#enc:c=avc:fintra=2:b=200k:#Representation=2
Please let us know if you have any questions!

Related

How to change a track ID with ffmpeg or MP4Box?

I need to change the id of a video track in an mp4 container and of course without re-encoding. How can I do that with ffmpeg or MP4Box ? Is that even possible ?
With MP4Box you can fine-tune these parameters (more in MP4Box -h general):
-set-track-id id1:id2 changes the id of a track from id1 to id2
-swap-track-id id1:id2 swaps the IDs of the identified tracks
Example:
inplace: MP4Box -set-track-id 100:101 file.mp4
new file: MP4Box -set-track-id 100:101 file.mp4 -out new.mp4

Playing audio.mpd and video.mpd together in dash.js

For MPEG DASH streaming, I have audio.mpd and video.mpd separately for a video.mp4 file generated using following command.
MP4Box -dash 5000 -frag 5000 -rap -bs-switching no -profile dashavc264:live -segment-name ./video/$2_segment_ -out ./mpds/$2_video.mpd $2.mp4#video
MP4Box -dash 5000 -frag 5000 -rap -bs-switching no -profile dashavc264:live -segment-name ./audio/$2_segment_ -out ./mpds/$2_audio.mpd $2.mp4#audio
Each mpd plays separately in dash.js. Is it possible to play them together using dash.js?
Or is there any way to merge both using MP4Box?
2 options:
MPD are XML. So you can easily post-process them to merge. Practically the MPD should be nearly identical. Insert both <AdaptationSet>s in a new MPD under <Period>.
Alternately execute the following command-line to make it in one pass: MP4Box -dash 5000 -frag 5000 -rap -bs-switching no -profile dashavc264:live -segment-name $2_segment_ -out ./mpds/$2_video.mpd $2.mp4#video:baseURL=video $2.mp4#audio:baseURL=audio

Single Manifest file for different audio and video segments created using MP4Box (MPEG DASH)

I have three questions
1) Does dash.js support audio and video content multiplexed in a single segment?
2) If not how to merge audio.mpd and video.mpd created using MP4Box into a single out.mpd, that is supported by dash.js player?
3) It works if AdaptationSet is copied manually from audio.mpd and placed in video.mpd and video.mpd is played using dash.js. How to automate it?
MP4Box -dash 4000 -frag 4000 -rap -bs-switching no -profile dashavc264:live -segment-name ./video/segment_ -out video.mpd video.mp4#video
MP4Box -dash 4000 -frag 4000 -rap -bs-switching no -profile dashavc264:live -segment-name ./audio/segment_ -out audio.mpd video.mp4#audio
Answers:
No, dash.js by intention does not support muxed audio/video segments. This is because it is the reference player for the DASH Industry Forum (DASH IF). The DASH IF publish interop guidelines http://dashif.org/guidelines/ designed to simply and standardize deployments of MPEG DASH. One of those restrictions is that muxed segments are not supported. This is the current state. However, within dash.js we are looking at adding a mode of operation such that we will allow both muxed playback and playlist-based addressing (another IOP restriction) if the player is operating in non-reference-player mode. This should be implemented in either the 2.2 release or later.
2+3: to use mp4box to package to demuxed segments from a muxed source called muxed.mp4, try
MP4Box -dash 4000 -frag 4000 -rap -bs-switching no -profile dashavc264:live -segment-name ./video/segment_ -out video.mpd muxed.mp4#video muxed.mp4#audio
Cheers
Will
You can do it using MP4Box twice:
MP4Box -dash 4000 -frag 4000 -rap -bs-switching no -profile dashavc264:live -segment-name ./video/v_ -out video.mpd muxed.mp4#audio muxed.mp4#video
to create video segments
MP4Box -dash 4000 -frag 4000 -rap -bs-switching no -profile dashavc264:live -segment-name ./video/v_ -out video.mpd muxed.mp4#video muxed.mp4#audio
to create audio segments
Modify video.mpd
change the video_init.mp4 & video segment name
That's it.
In order to produce one MPD file containing details about separate audio and video segments using MP4Box, just remove the -segment-name option and it's value. So your command should look like this
MP4Box -dash 4000 -frag 4000 -rap -bs-switching no -profile dashavc264:live
-url-template video.mp4 audio.mp4 -out manifest.mpd

Generating MPEG DASH videos which are compilant with HbbTV 1.5 standard

I am looking for a the command line options for ffmpeg, DASHEncoder and MP4Box to generate HbbTV 1.5 compilant MPEG DASH videos.
See http://www.hbbtv.org/pages/about_hbbtv/specification.php for more information on the HbbTV 1.5 standard and its DASH profile which is used there.
When it comes to DASH-streaming for HbbTV 1.5 devices, the input arguments for FFmpeg and MP4Box depend on each other. Options to encode a video with FFmpeg for HbbTV terminals could be
FFmpeg -i input.avi -f h264 -c:v libx264 -aspect 16:9 -preset slow -profile:v high -r 50 -g 100 -force_key_frames "expr:gte(t,n_forced*2)" -b:v 3584k -maxrate 3584k -bufsize 7168k -x264opts nal-hrd=vbr -c:a libfdk_aac -b:a 192k -ar 48k -ac 2 output.mp4
In order to make sure that the video will be played back smoothly, the arguments for the bitrate and maxrate of the video should be the same. In addition, the bufsize argument should not be bigger then twice the bitrate.
The arguments for the the GOP and force_key_frames options depend on the length of segments you create with MP4Box.
It is recommended that each segment starts with a keyframe and that one segment includes an entire GOP. in this example, the length for each segment should be at least 2 seconds, or a multiple of 2 seconds.
Options to segment the encoded video could be
MP4Box -dash 2000 -frag 2000 -rap -profile live -segment-name video$Number$ -segment-ext m4s -out video.mpd input.mp4#video:id=1
MP4Box -dash 2000 -frag 2000 -rap -profile live -segment-name audio$Number$ -segment-ext m4s -out audio.mpd input.mp4#audio:id=2
Now each segment and each fragment within the segment has a length of 2 seconds. The required profile for HbbTV devices is the live profile.
If you are looking for adaptive MPEG-DASH or legacy test streams for HbbTV devices, you can find a wide variaty of testcases by following this link: http://av-standard.irt.de/wiki/index.php/Referenzclips

Can you splice a 1 min clip out of a larger file, without transcoding it?

I have a site that allows people to upload large video files in various formats (avi, mp4, mkv and flv). I need to generate a 1 minute "sample" from the larger file that has been uploaded, and the sample needs to be in the same format, have the same frame dimensions and bit-rate as the original file. Is there a way to simply cut out a section of the file into a new file? Preferably in ffmpeg (or any other tool if ffmpeg is impossible).
First you'll want to understand how video files actually work. Here's a set of tutorials explaining that: Overly Simplistic Guide to Internet Video.
Then, you can try a variety of tools that may help with slicing out a sample. One is flvtool (if your input is FLV) or FFmpeg. With FFmpeg you can specify a start time and stop time, and it will attempt to cut out just what you ask for (but it will have to find the nearest key-frame to begin slicing at).
Here's the FFmpeg command to read a file called input.flv, start 15 seconds into the video, and then cut out the next 60 seconds, but otherwise keep the same parameters for the audio code and video codec, and write it to an output file:
ffmpeg -i input.flv -ss 15 -t 60 -acodec copy -vcodec copy output.flv
Finally if you want you can write computer code in C or C++ (using FFmpeg's libav libraries) or Java (using Xuggler) to programatically do this, but that's pretty advanced for your use case.
If you are having problems keeping auto and video synced up as I was, the following may help (found on another website):
ffmpeg -sameq -i file.flv -ss 00:01:00 -t 00:00:30 -ac 2 -r 25 -copyts output.flv
As Evan notes, the approach in the accepted answer can result in loss of A/V sync. However his solution is not correct because -sameq was removed.
As stated at https://trac.ffmpeg.org/wiki/Seeking the -ss option should come before -i not after. This fixed the issue for me.
Next option is to use -fs switch. Example:
ff -i ip.mkv -fs 500M -c copy ~/Movies/reservoir/carbohydrates.mkv
Extract 500 megabytes (500×1000×1000 bytes + ‘muxing overhead’) off selected source.
–based on filesize, as you can tell
One love. And respect.

Resources