Skip to content

Instantly share code, notes, and snippets.

@teocci
Last active May 3, 2018 10:33
Show Gist options
  • Save teocci/e22195e6a9b575d9a7f5ae8a0d07a76b to your computer and use it in GitHub Desktop.
Save teocci/e22195e6a9b575d9a7f5ae8a0d07a76b to your computer and use it in GitHub Desktop.

Parameters

I tested on ffmpeg 3.2.x Hypatia.

Container: MP4

Parameter YouTube recommends setting
-movflags faststart moov atom at the front of the file (Fast Start)

Video codec: H.264

Parameter YouTube recommends setting
-profile:v high High Profile
-bf 2 2 consecutive B frames
-g 30 Closed GOP. GOP of half the frame rate.
-coder 1 CABAC
-crf 18 Variable bitrate.
-pix_fmt yuv420p Chroma subsampling: 4:2:0

Audio codec: AAC-LC

Parameter YouTube recommends setting
-c:a aac -profile:a aac_low AAC-LC
-b:a 384k Recommended audio bitrates for uploads: Stereo 384 kbps
#/bin/sh
ffmpeg -i input -c:v libx264 -preset slow -profile:v high \
-crf 18 -coder 1 -pix_fmt yuv420p -movflags +faststart -g 30 -bf 2 \
-c:a aac -b:a 384k -profile:a aac_low output

Trim Video Start Time and End Time

ffmpeg -ss 3:59:10 -i $(youtube-dl -f 22 -g 'https://www.youtube.com/watch?v=mMZriSvaVP8') \
-t 3:06:40 -c copy output.mp4

ffmpeg combine seperate audio and video files into a single video

copy the audio and video tracks

ffmpeg -i audio.aiff -i video.mov \
-acodec copy -vcodec copy -f mp4 avcombined.mp4

encode the audio as aac and copy the video track without encoding it. if its the h264 codec

ffmpeg -i audio.aiff -i video.mov \
-acodec libfaac -ac 2 -ar 48000 -ab 160k \
-vcodec copy -f mp4 avcombined.mp4
ffmpeg -i audio.wav -i video.mp4 \
-acodec copy -vcodec copy \
-f mkv output.mkv
ffmpeg -ss 00:00:10 -t 5 -i "video.mp4" \
-ss 0:00:01 -t 5 -i "music.m4a" \
-map 0:v:0 -map 1:a:0 \
-y output.mp4
ffmpeg.exe -i AudioT.m4a -i VideoT.mp4 \
-acodec copy -vcodec copy \
muxed.mp4

how mix a video and audio ffmpeg 2018 command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment