Convert Video For Streaming
ffmpeg -y -i FILE_NAME.wmv -c:v libx264 -c:a aac -coder 1 -b:v 500k -threads 0 -b:a 96k FILE_NAME.mp4
if you want to scale the video to a specific size, use -vf scale option, for example
ffmpeg -y -i FILE_NAME.wmv -vf scale=720:480 -c:v libx264 -c:a aac -coder 1 -b:v 500k -threads 0 -b:a 96k FILE_NAME.mp4
Inject metadata
qt-faststart FILE_NAME.mp4 FILE_NAME-meta.mp4
Convert Video to MP4
This is verified method, and works good, i converted many videos, no quality lose
ffmpeg -i FILE_NAME.INPUT_EXTN -crf 25.0 -c:v libx264 -c:a libfaac -ar 48000 -b:a 160k -coder 1 -threads 0 FILE_NAME_nm.mp4
If you get error related to libfaac, try changing it with aac.
To cut a video during transcoding
time ffmpeg -ss 00:34:00 -t 00:02:00 -i FILE_NAME.INPUT_EXTN -crf 25.0 -c:v libx264 -c:a libfaac -ar 48000 -b:a 160k -coder 1 -threads 0 FILE_NAME_nm.mp4
Other Methods, Need to experiment
To convert video to H.264 (mp4) format
ffmpeg -i 'input.mpg' -acodec libfaac -ab 96k -vcodec libx264 -vpre hq -crf 22 -threads 0 output.mp4
ffmpeg -i 'input.mpg' -vcodec libx264 -vpre hq -b 1M -bt 1M -threads 0 outfile.mp4
ffmpeg -i test.avi -acodec libfaac -ab 128k -ar 44100 -s 704x400 -r 20 -vcodec libx264 -b 256000 -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me_method umh -subq 5 -trellis 1 -refs 2 -bf 1 -coder 1 -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 256000 -maxrate 4M -bufsize 4M -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 21 test.mp4
ffmpeg -y -i source.avi -vcodec libx264 -b BITRATE -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -flags2 +mixed_refs -me umh -subq 5 -trellis 1 -refs 5 -bf 3 -b_strategy 1 -coder 1 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt "$vbitrate" -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -level 41 -acodec libfaac -ac 2 -ar 48000 -ab "$abitrate" -f mov out.mov
Using ffmpeg and x264
Example two-pass encoding script:
#!/bin/bash
# Two-Pass x264 Encoding Script
# Usage: ./264encode.sh input output.mp4
# Pass 1
ffmpeg -y -i $1 -pass 1 -b 512k -bt 512k -vcodec libx264 -an -threads 0 -coder 1 -flags +loop -cmp +chroma -partitions -parti8x8-parti4x4-partp8x8-partp4x4-partb8x8 -me_method dia -subq 1 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -bf 16 -refs 1 -directpred 1 -bidir_refine 0 -trellis 0 -flags2 -bpyramid-wpred-mixed_refs-dct8x8+fastpskip -f mp4 /dev/null
# Pass 2
ffmpeg -y -i $1 -pass 2 -b 512k -bt 512k -vcodec libx264 -acodec libfaac -ab 128k -ac 2 -threads 0 -coder 1 -flags +loop -cmp +chroma -partitions +parti8x8+parti4x4+partp8x8+partb8x8 -me_method umh -subq 8 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -bf 16 -refs 4 -directpred 3 -trellis 1 -flags2 +bpyramid+wpred+mixed_refs+dct8x8+fastpskip -f mp4 $2
To use
sh 264encode.sh input.avi output.mp4
See ffmpeg
Leave a Reply