ffmpeg : 4K BluRay to 1080p x264 - ffmpeg

I'm trying to encode a 1080p x264 from a 4K BluRay. The problem is that source has bit-depth : 10 bits and i want output bit-depth 8 bits ...
3840x2160 (input) ==> 3840x1600 (cropped to delete black bars) ==> 1920x800 (resized)
If i use x264 0.155.2901 7d0ff22 compiled with bit-depth=all
ffmpeg -y -i input4K.m2ts -c:v libx264 -preset slow -crf 18 -x264-params me=umh:merange=24:trellis=1:level=4.1:ref=5 -filter:v "crop=3840:1600:0:280, scale=1920:800" -an "1080_"$output.mkv
it works but the output file is not 8bit, Format profile : High 10#L4.1
how to get format profile = High #L4.1 ? (force 8 bits output)
If i usex264 compiled with bit-depth=8, it tells me it can't read source.

This should work:
ffmpeg -y -i input4K.m2ts -c:v libx264 -pix_fmt yuv420p -preset slow -crf 18 -x264-params me=umh:merange=24:trellis=1:level=4.1:ref=5 -filter:v "crop=3840:1600:0:280, scale=1920:800" -an "1080_"$output.mkv

Related

Targeting a specific file size in vp8+vorbis encoding using ffmpeg

I have a couple videos that I want to encode to vp8 for video and Vorbis for audio. This is the FFmpeg command I'm currently using:
ffmpeg -y -i input.mp4 -map 0:v:0 -s 640x360 -filter:v fps=20 -c:v libvpx -crf 10 -b:v 200k -map 0:a:0 -b:a 48k -c:a libvorbis output.webm
I want to have control over output file size and limit it to 3MB without clipping the video, but instead, lose quality. so I cant use -fs 3MB.
How can I determine the file size based on video and audio bitrates and duration?
How can I limit the file size without clipping?
Example for 10 second input with an output just under 3 MB output:
3 MB * 8000 / 10 seconds - 48kb audio bitrate - 1% muxing overhead = -b:v 2328k
Encode with two passes when targeting specific output file size:
ffmpeg -y -i input.mp4 -map 0:v:0 -filter:v "scale=640:360,fps=20" -c:v libvpx -b:v 2328k -pass 1 output.webm
ffmpeg -y -i input.mp4 -map 0:v:0 -filter:v "scale=640:360,fps=20" -c:v libvpx -b:v 2328k -map 0:a:0 -c:a libvorbis -b:a 48k -pass 2 output.webm
See:
Get duration with ffprobe
FFmpeg Wiki: VP8

how to convert an 720p file to 360p using ffmpeg with the help of gpu

i want to convert a 720 p video into 360 p video with the help of GPU. i am using this command: "ffmpeg -y -vsync 0 -hwaccel cuda -hwaccel_output_format cuda -resize 480x360 -i input -c:a copy -c:v h264_nvenc -b:v 249K output"
,but the output file is larger than input file.
i need to reduce the size of input file.
I managed to compress 720 P video with size 110MB to be 15 MB with below command:
ffmpeg -i input.mp4 -vf scale=-1:360 -c:v libx264 -crf 18 -preset veryslow -c:a copy output.mp4

How to specify how lossy/lossless a .webm conversion will be (in ffmpeg)?

I can't seem to understand how to make the conversion lossless (or at least visually lossless)? The outputs have some fast moving parts at times, and the output would become blocky; I would like to keep it as lossless as possible, while still maintaining some compression. What would I have to tweak at the command line? Thanks you~
ffmpeg -c:v libvpx-vp9 -i in.webm -c:v libvpx -vf scale=400:416,hue=h=45:s=1 -auto-alt-ref 0 out.webm
According to FFmpeg Wiki: VP9, "two-pass is the recommended encoding method for libvpx-vp9 as some quality-enhancing encoder features are only available in 2-pass mode". Example of your command:
ffmpeg -c:v libvpx-vp9 -i in.webm -c:v libvpx-vp9 -vf scale=400:416,hue=h=45:s=1 -b:v 0 -crf 30 -pass 1 -an -f null /dev/null
ffmpeg -c:v libvpx-vp9 -i in.webm -c:v libvpx-vp9 -vf scale=400:416,hue=h=45:s=1 -b:v 0 -crf 30 -pass 2 -c:a copy output.webm
The CRF value can be from 0–63. Lower values mean better quality. Recommended values range from 15–35, with 31 being recommended for 1080p HD video. For more info see Google - Getting Started with VP9.

FFMPEG: Combine "Create video from images" + scale to x + add audio + overlay logo

I´m working on a webcam-project. It is for generating timelapse videos of sunset/sundown.
I´m using a raspberrypi to generate them with gphoto2 + DSLR.
At the end of the day the images should get to an video, with audio and an overlay logo.
And it should be scaled to 1920 pixel.
I got a nice solution an it worked.
Producing the timelapse video an scale it:
ffmpeg -y -framerate 25 -start_number 0000001 -i /var/www/html/webcam/2020-01-05_bilder/%7d.jpg -vf scale=1920:-1 -pix_fmt yuv420p /var/www/html/webcam/2020-01-05-tag-output-1920.mp4
Taking the output of (1) and add an overlay-logo, add audio
ffmpeg -y -i '/var/www/html/webcam/2020-01-05-tag-output-1920.mp4'
-i '/var/www/html/webcam-scripts/graphics/logo.png'
-i '/var/www/html/webcam-scripts/sounds/chill_time_5.mp3'
-shortest -filter_complex '[1][0]scale2ref=h=ow/mdar:w=iw/6[#A logo][liebfrauen]; [#A logo]format=argb,colorchannelmixer=aa=0.95[#B logo transparent]; [liebfrauen][#B logo transparent] overlay=(main_w-w)-(main_w*0.05):(main_h-h)-(main_h*0.01)'
-c:v libx264 -crf 18 -preset slow -pix_fmt yuv420p -c:a aac -strict -2
'/var/www/html/webcam/2020-01-05-tag-1920.mp4
I tried to combine both actions, but I get an error:
ffmpeg -y -framerate 25 -start_number 0000001 -i '/var/www/html/webcam/2020-01-05_bilder/%7d.jpg' -vf scale=1920:-1 -pix_fmt yuv420p -i '/var/www/html/webcam-scripts/graphics/logo.png' -i '/var/www/html/webcam-scripts/sounds/chill_time_5.mp3' -shortest -filter_complex '[1][0]scale2ref=h=ow/mdar:w=iw/6[#A logo][liebfrauen]; [#A logo]format=argb,colorchannelmixer=aa=0.95[#B logo transparent]; [liebfrauen][#B logo transparent] overlay=(main_w-w)-(main_w*0.05):(main_h-h)-(main_h*0.01)' -c:v libx264 -crf 18 -preset slow -pix_fmt yuv420p -c:a aac -strict -2 '/var/www/html/webcam/2020-01-05-tag-1920.mp4'
Error: Filtergraph 'scale=720:-1' was specified through the -vf/-af/-filter option for output stream 0:0, which is fed from a complex filtergraph.
-vf/-af/-filter and -filter_complex cannot be used together for the same stream.
Isn`t it possible to combine these inputs and scale it? Or ... Where is my misunderstanding?
Don't mix -vf and -filter_complex. Do all filtering in one filtergraph.
ffmpeg -y -framerate 25 -i '/var/www/html/webcam/2020-01-05_bilder/%7d.jpg' -i '/var/www/html/webcam-scripts/graphics/logo.png' -i '/var/www/html/webcam-scripts/sounds/chill_time_5.mp3' -filter_complex '[0]scale=1920:-2[v0];[1][v0]scale2ref=h=ow/mdar:w=iw/6[#A logo][liebfrauen]; [#A logo]format=argb,colorchannelmixer=aa=0.95[#B logo transparent]; [liebfrauen][#B logo transparent] overlay=(main_w-w)-(main_w*0.05):(main_h-h)-(main_h*0.01),format=yuv420p' -c:v libx264 -crf 18 -preset slow -c:a aac -shortest '/var/www/html/webcam/2020-01-05-tag-1920.mp4'
No need for -strict -2. It does nothing for modern ffmpeg.
I replaced -pix_fmt yuv420p with format=yuv420p so it is more organized.
-start_number 0000001 is not needed because 1 is the default.

encoding jpeg as h264 video

I am using the following command to encode an AVI to an H264 video for use in an HTML5 video tag:
ffmpeg -y -i "test.avi" -vcodec libx264 -vpre slow -vpre baseline -g 30 "out.mp4"
And this works just fine. But I also want to create a placeholder video (long story) from a single still image, so I do this:
ffmpeg -y -i "test.jpg" -vcodec libx264 -vpre slow -vpre baseline -g 30 "out.mp4"
And this doesn't work. What gives?
EDIT: After trying LordNeckbeards answer, here is my full output: http://pastebin.com/axhKpkLx
Example for a 10 second output:
ffmpeg -loop 1 -framerate 24 -i input.jpg -c:v libx264 -preset slow -tune stillimage -crf 24 -vf format=yuv420p -t 10 -movflags +faststart output.mp4
Same thing but with audio. The output duration will match the input audio duration:
ffmpeg -loop 1 -framerate 24 -i input.jpg -i audio.mp3 -c:v libx264 -preset slow -tune stillimage -crf 24 -vf format=yuv420p -c:a aac -shortest -movflags +faststart output.mp4
-loop 1 loops the image input.
-framerate sets the frame rate of the image input. Default is 25. Some players have issues with low frame rates so a value over 6 or so is recommended.
-i input.jpg the input.
-c:v libx264 the H.264 video encoder.
-preset x264 encoding preset. Use the slowest one you can.
-tune x264 tuning for various adjustments to fit specific situations.
-crf for quality. A lower value results in higher quality. Use the highest value that still provides an acceptable quality to you. Default is 23.
-vf format=yuv420p outputs the pixel format as yuv420p. This ensures the output uses a widely acceptable chroma sub-sampling scheme. Recommended for libx264 when encoding from images.
-c:a aac the AAC audio encoder. If your input is already AAC or M4A then use -c:a copy instead to stream copy instead of re-encode.
-t 10 (in the first example) makes a 10 second output. Needed because the image is looping indefinitely.
-shortest (in the second example) makes the output the same duration as the shortest input. In this case it is the audio since the image is looping indefinitely.
-movflags +faststart relocates the moov atom to the beginning of the file after encoding is finished. Allows playback to begin faster in progressive download playing; otherwise the whole video must be downloaded before playing.
-profile:v main (optional) some devices can't handle High profile.
See FFmpeg Wiki: H.264 for more info.

Resources