Quick conversion of mp4 to hls using ffmpeg - ffmpeg

I need to convert huge video(around 2-4GB) using ffmpeg from mp4 to hls format.
The following takes very long to run, is there any quick conversion flag in ffmpeg.
ffmpeg -i ad1.mp4 -strict -2 -profile:v baseline -level 3.0 -start_number 0 -hls_list_size 0 -hls_segment_filename 'sample-%06d.ts' -f hls sample.m3u8

Assuming ffmpeg is using the x264 encoder, change the preset.
ffmpeg -i ad1.mp4 -strict -2 -preset:v veryfast -profile:v baseline ...
This should increase speed by 100% for moderate difference in bitrate. There are other presets like superfast but filesize will increase appreciably.

Related

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.

can i use -crf and -s option in one command with ffmpeg

I want to create video streaming for phone. To do that i use ffmpeg to convert video into hls. For now i can convert video to hls using this command:
ffmpeg -y -i video.mp4 -profile:v
baseline -level 3.0 -crf 51 -start_number 0 -hls_time 10
-hls_list_size 0 -f hls video.m3u8.
I know i can reduce video image size by using this command:
ffmpeg -y -i video.mp4 -profile:v
baseline -level 3.0 -s 640x360 -r 20 -start_number 0 -hls_time 10
-hls_list_size 0 -f hls video.m3u8
can i use both -s and -crf in one command?
Because i'm streaming for phone. so size is my main concern.
Yes you can, crf stands for constant rate factor which is unrelated to the dimensions of your output. Generally speaking you’ll also get a conversion failed in your console when passing invalid flags.

ffmpeg mp4 to hls restrict output chunk size instead of duration

I need to convert mp4 video hls format in which I want to limit the output size of each chunk. I am able to restrict the chunk size to duration but it is not mandatory instead I am interested in size.
I am using below command to convert.
ffmpeg -i sample.mp4 -strict -2 -preset:v veryfast -profile:v baseline -level 3.0 -s 640x360 -start_number 0 -hls_list_size 0 -force_key_frames expr:'gte(t,n_forced*5)' -hls_time 5 -hls_segment_filename 'sample-%06d.ts' -f hls sample.m3u8
How can I restrict the chunk size to max 500Kb?

ffmpeg - Convert MP4 to WebM, poor results

I am trying to encode a video to webm for playing through a HTML5 video tag. I have these settings...
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:a 128k -b:v 1M -c:a libopus output.webm
The results aren't great, video has lost lot's of it's sharpness. Looking at the original file I can see the bitrate is 1694kb/s.
Are there any settings I can add or change to improve the output? Would maybe a 2 pass encode improve things?
Try with
ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 30 -b:v 0 -b:a 128k -c:a libopus output.webm
Adjust the CRF value till the quality/size tradeoff is ok. Lower values produce bigger but better files.
Try to run two passes:
ffmpeg -i file.mp4 -b:v 0 -crf 30 -pass 1 -an -f webm -y /dev/null
ffmpeg -i file.mp4 -b:v 0 -crf 30 -pass 2 output.webm
From - https://trac.ffmpeg.org/wiki/Encode/VP9

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