ffmpeg-to-mp4.sh (1019B)
1 #!/bin/sh 2 output="${1%.*}.mp4" 3 4 # From media9 LaTeX package documentation. 5 # Generates sufficient keyframes to allow for precise seeking within video. 6 # The scale argument ensures that dimensions are divisible by 2, a requirement 7 # for MP4 videos using H.264. 8 ffmpeg -i "$1" \ 9 -vf scale="trunc(iw/2)*2:trunc(ih/2)*2" \ 10 -c:v libx264 -profile:v high -pix_fmt yuv420p \ 11 -g 30 -r 30 -y \ 12 "$output" 13 14 #ffmpeg -i movie.avi -sameq -vcodec libx264 -x264opts keyint=25 \ 15 #-acodec libfaac -b:a 128k -vcodec mpeg4 -b:v 1200k -flags +aic+mv4 \ 16 17 # constant bitrate: 18 #ffmpeg -i $1 -vcodec libx264 -crf 20 $output 19 20 # Output first frame as an image 21 ffmpeg -i "$1" -y -vframes 1 -f image2 "${output%.*}.png" 22 23 # Output last frame as an image 24 #lastframe_index=$(ffprobe -show_streams "$1" 2> /dev/null | \ 25 # grep nb_frames | head -1 | cut -d \= -f 2) 26 #ffmpeg -i $1 -vf "select='eq(n,$lastframe_index)'" -vframes 1 -f image2 \ 27 # ${output%.*}-last.png 28 29 echo "$output" 30 31 if [ "$2" = "cleanup" ]; then 32 rm "${1%.*}.png" 33 rm "${1}" 34 fi