FFmpeg Commander

https://ffmpeg.org/ffmpeg-all.html

FFmpeg批量复制视频流

set -e
for file in *.ts; do
    file_name=${file%.*}
    file_extension=${file#*.}
    input=$PWD/$file_name.$file_extension
    output=$PWD/$file_name'_output.mp4'
    ffmpeg -hide_banner -y -i "${input}" -c:v copy -c:a copy "${output}"
    mkdir -p $PWD/tmp
    echo -e "\033[32m $(mv -v "$input" "$PWD"/tmp) \033[0m"
done

将 moov 原子移动到文件开头

set -e
for file in *.ts; do
    file_name=${file%.*}
    file_extension=${file#*.}
    input=$PWD/$file_name.$file_extension
    output=$PWD/$file_name'_output.mp4'
    ffmpeg -hide_banner -y -i "${input}" -movflags faststart -acodec copy -vcodec copy "${output}"
    mkdir -p $PWD/tmp
    echo -e "\033[32m $(mv -v "$input" "$PWD"/tmp) \033[0m"
done

首屏视频的优化过程

The mov/mp4/ismv muxer supports fragmentation. Normally, a MOV/MP4 file has all the metadata about all packets stored in one location (written at the end of the file, it can be moved to the start for better playback by adding +faststart to the -movflags, or using the qt-faststart tool).

https://ffmpeg.org/ffmpeg-all.html#mov_002c-mp4_002c-ismv
https://segmentfault.com/a/1190000021578572

将 moov 原子移动到文件开头

ffmpeg -i input.mp4 -movflags faststart -acodec copy -vcodec copy output.mp4

合并音频和视频

ffmpeg -i [video] -i [audio] -vcodec copy -acodec copy output.mp4
ffmpeg -i video.mp4 -i audio.mp3 -c copy -map 0:v:0 -map 1:a:0 -shortest output.mp4
ffmpeg -i video.mp4 -i audio.mp3 -vcodec copy -filter_complex amix -map 0:v -map 0:a -map 1:a -shortest output.mp4