Generating MPEG DASH videos which are compilant with HbbTV 1.5 standard - ffmpeg

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

Related

Live stream prerecorded video to YouTube using FFMPEG with 4500 kbps bitrate

I tried various ways to make a live streaming script with a bit rate according to YouTube's recommendation of 4500 Kbps bit rate.
The code:
ffmpeg -re -stream_loop -1 -i live1.mp4 -c copy -preset veryfast -b:v 7000k -maxrate 3000k -bufsize 6000k -pix_fmt yuv420p -g 50 -c:a aac -b:a 160k -ac 2 -ar 44100 -f flv -flvflags no_duration_filesize rtmp://a.rtmp.youtube.com/live2/(streamkey)
and in my current code, there is an error when live: Use a keyframe frequency of four seconds or less. Currently, keyframes are sent infrequently which can cause buffering. The current keyframe frequency is 5.0 seconds. Please note that errors in the transfer process can cause the size of the GOP (group of images) to be incorrect.
How to fix my code?
I've tried several ways, but the bit rate is still high, and the error is in YouTube Studio

FFmpeg: Get better encoding out of my function

I needed some assistance on my task.
I am using FFmpeg to burn time and the channel name onto the video.
My goal is to record a stream that is html5 compatible with the following settings:
Video wrapper MP4
Video codec H.264
Bitrate 1Mbps
Audio codec AAC
Audio bitrate 128Kbps
And GPU encoding.
This is what I am using:
ffmpeg -hwaccel cuvid -y -i {udp} -vf "drawtext=fontfile=calibrib.tff:fontsize=25:text='{ChannelName} %{localtime}': x=10: y=10: fontcolor=white: box=1: boxcolor=0x000000" -pix_fmt yuv420p -vsync 1 -c:v h264_nvenc -r 25 -threads 0 -b:v 1M -profile:v main -minrate 1M -maxrate 1M -bufsize 10M -sc_threshold 0 -c:a aac -b:a 128k -ac 2 -ar 44100 -af "aresample=async=1:min_hard_comp=0.100000:first_pts=0" -bsf:v h264_mp4toannexb -t 00:30:00 {output}\{ChannelName}\{ChannelName}_{year}_{monthno}_{day}__{Hours}_{Minutes}_{Seconds}.mp4
{ChannelName}_{year}_{monthno}_{day}__{Hours}_{Minutes}_{Seconds} are all variable holding information.
{udp} holds the UDP stream link.
I have done it this way as I have multiple UDP stream recording.
Although this works, is there a better way for me to do this keeping in the -vf as I need the time and channel name.
Currently, this uses between 0.8% to 1.9% GPU on my Quadro P4000. I don't want to use more than this as I have more than 30 streams.
Here are some of the suggestion
-profile:v use Constrained Baseline Profile or Baseline Profile - as most of the Browser or HTML will support.
Check How many parallel instances of the Encoder you can run on GPU - Quadro P4000, remaining you can run on cpu.
Based on the resolution & fps you can decide the video bitrate of encoding range min & max bitrate. (-b:v 1M -minrate 1M -maxrate 1M) - refer : https://trac.ffmpeg.org/wiki/Limiting%20the%20output%20bitrate
-sc_threshold (FFmpeg)
Adjusts the sensitivity of x264's scenecut detection. Rarely needs to be adjusted. Recommended default: 40

FFMPEG: Youtube streaming quality and speed issues

I am trying to make a reliable stream from my Icecast/Shoutcast servers to Youtube live. The command that I use is:
ffmpeg -v verbose -framerate 30 -loop 1 -i /var/image.jpg -re -i http://127.0.0.1:4700/radio -c:v libx264 -preset ultrafast -b:v 2250k -maxrate 6000k -bufsize 6000k -c:a copy -ab 128k -s 1920x1080 -framerate 30 -g 60 -keyint_min 60 -f flv rtmp://a.rtmp.youtube.com/live2/xxx
As you can see I am using recommended bitrate for Youtube, insert keyframes every 2 seconds and streaming at 30 frames per second.
The stream is working but after running for some time two thing are happening:
FFMPEG speed falls from 1x to something like 0.998x
Youtube starts complaining that video stream speed is slow, markes the quality as bad and sometimes video starts buffering.
Why is this happening? CPU load is normal, connectivity is ok (the stream is running on a 1Gg/s dedicated server).
Since in my example above I am streaming a single image as a logo of the stream I also tried to generate a short 30 seconds video with that image and broadcast that video instead of an image, but that did not help as well.
The command I used for conversion:
ffmpeg -framerate 30 -loop 1 -i /var/image.jpg -c:v libx264 -preset ultrafast -tune stillimage -b:v 2250k -minrate 2250k -maxrate 6000k -bufsize 6000k -framerate 30 -g 60 -keyint_min 60 -t 30 out4.mp4
And broadcast with
ffmpeg -stream_loop -1 -i out4.mp4 -re -i http://127.0.0.1:4700/radio -c:v copy -c:a copy -framerate 30 -g 60 -keyint_min 60 -f flv rtmp://a.rtmp.youtube.com/live2/xxx
ffmpeg version is 4.1.1
Are you sure that your original stream is really keeping up with the wall-clock?
Depending on how it's encoded there are possibilities that it gets heavily skewed. This ultimately leads to buffer under (or overruns if it's too fast) and the player complaining/skipping.
Can you try and dump several hours worth of stream to a file and then stream that with FFmpeg? If that works, then it's a strong indication that your original stream timing (sample rate) is off.
Getting the sample rate right is why professional/expensive sound cards use high precision Quartz-Crystal controlled oscillators. Purely virtual processing (e.g. files get encoded into a stream) can easily get skewed, especially inside virtual machines. Also, cheap USB sound cards are often among the worst offenders in terms of frequency accuracy and stability.
FFmpeg might have an option to deal with too slow input. Keywords could be 'padding' or 'missing samples'.
Youtube's error saying "...buffer....." is not a buffer issue on your PC, but simply data you are sending to youtube is too small.
1)note that [-preset ultrafast] and [-preset fast] does not make big difference.
2) change your ffmpeg comannd for broadcast one. like, [-b:v 2250k] to [-b:v 15000k],and set fps to 12→[-r 12] option.
I's gonna be.
ffmpeg -stream_loop -1 -i out4.mp4 -re -i http://127.0.0.1:4700/radio -preset fast -r 12 -framerate 30 -g 60 -video_track_timescale 1000 -b:v 15000k -f flv rtmp://a.rtmp.youtube.com/live2/xxx
I hope this will be good for you !!(^v^)Y

Transcoding FLV to MP4 with ffmpeg very slow

I am trying to support the recording of webcam video on our website, which I then need to transcode to MP4 and WebM to support HTML5 playback. I have ffmpeg 1.2 installed on our server, and have the whole process running fairly well.
The one problem I do have though is transcoding FLV to MP4. it is unacceptably slow, e.g. an 8 second FLV takes about 2.5 mins to transcode!
The ffmpeg command I am using is:
ffmpeg -y -i webcam.flv -c:a libfaac -ac 2 -b:a 64k -ar 44100 -c:v libx264 \
-b:v 350k webcam.mp4
There are so many ffmpeg params, I am a bit lost as to the best way forward with this issue. You can download a test flv from here:
dropbox.com/s/hhd6uhdiuhk800w/webcam.flv
By comparison, transcoding to WebM takes about 5 seconds:
ffmpeg -y -i webcam.flv -c:a libvorbis -ac 2 -b:a 64k -ar 44100 -c:v libvpx \
-b:v 350k -metadata:s:v:0 rotate=0 webcam.webm
ok i found the answer. i had a closer look at the ffmpeg output, and noticed:
[mp4 # 0xa0060c0] Frame rate very high for a muxer not efficiently supporting it.
Please consider specifying a lower framerate, a different muxer or -vsync 2
doh. so i added "-vsync 2" as the last parameter before the output file and it worked a charm, took transcoding time down to about 10 secs! very happy.
working out "generalised" ffmpeg settings for all types of a/v input still seems like black magic to me...

Why the converted videos file size is greater than original file size?

I am using ffmpeg to convert the videos into mp4.Its working fine and its playing with high quality.No problem.But the worst case is I uploaded 14Mb file and after converting it goes to 30 Mb file.I am using the following the script to convert
exec("ffmpeg -i videowithaudio.flv -vcodec libx264 -vpre hq -vpre ipod640 -b 250k -bt 50k -acodec libfaac -ab 56k -ac 2 -s 480x320 video_out_file.mp4 > output1.txt 2> apperror1.txt"); //webkit compatible
I am using PHP for executing this command.Could you please help me how to reduce the file size from this 30Mb (nearly to uploaded file size is ok) with same quality.
Files converted from flv to mp4 will always have greater size than the source file. Generally flv files are smaller than other formats, thats why youtube converts all files to flv.
you can use -sameq parameter to retain the quality of video and lesser file size of resulting output file.
Example 1:
ffmpeg -i input.flv -sameq -ar 22050 output.mp4
Example 2:
exec("/usr/bin/ffmpeg -y -i input.flv -acodec libfaac -sameq -ar 44100 -ab 96k -coder ac -me_range 16 -subq 5 -sc_threshold 40 -b 1600k -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -i_qfactor 0.71 -keyint_min 25 -b_strategy 1 -g 250 -r 20 output.mp4");
I created this command by searching alot and this fulfills my requirements, using this you can get a bit less file size but with same quality.
Hope this works for you also.
You should try playing around with your key frames rate (-g). Frames between key frames have only the pixels different from the previous key frame. If your key frames are too far apart, all pixels are present in middle frames (increasing size), too close and the number of key frames increases the file size.
Note that the optimal key frame rate will be different for each video, so you need to find a middle ground.
exec("ffmpeg -i videowithaudio.flv -vcodec libx264 -vpre hq -vpre ipod640 -b 250k -bt 50k -acodec libfaac -ab 56k -ac 2 -s 480x320 video_out_file.mp4 > output1.txt 2> apperror1.txt"); //webkit compatible
Important for the filesize, is the bitrate. The bitrate specifies how many bytes to use per second video. If you decrease the bitrate, the filesize will also become smaller.
You are currently using 250kbit/s video (-b 250k) and 56kbit/s audio (-ab 56k), so you have to decrease those numbers. For example you can try :-b 100k -ab 32k. But keep in mind that the quality will also decrease when you decrease the bitrate. If the quality becomes too bad, you can also decrease the framerate or frame size to increase the quality.

Resources