ffmpeg常用命令

ffmpeg常用命令

把当前目录下的所有m4a文件转成mp3

for foo in *.m4a; do ffmpeg -i "$foo" -acodec libmp3lame -aq 2 "${foo%.m4a}.mp3"; done

flac转320kbps音质的mp3(最高音质的mp3)

ffmpeg -i input.flac -ab 320k -map_metadata 0 -id3v2_version 3 output.mp3

压缩视频

ffmpeg -i /Users/bruce/Downloads/sample.mp4  -vcodec libx264 -preset fast -crf 28 -y -vf "scale=640:-1"  a.mp4

scale=640:-1 表示等比例缩放,宽缩放为640,高为-1表示自动根据比例缩放。


压缩当前目录下所有mp4文件

for foo in *.mp4; do ffmpeg -i "$foo" "${foo%}_optimized.mp4"; done

任何格式转h.264 mp4格式

ffmpeg -i IMG_1310.MOV -vcodec libx264 -y IMG_1310.mp4

从当前目录下的所有mkv视频中提取mp3

for i in *.mkv; do ffmpeg -i "$i" -b:a 320k -vn -f mp3 "${i%.mkv}.mp3"; done

把多个mp4视频合并成一个

#先进入要合并的视频所在目录,然后把所有视频按顺序,转成1.ts、2.ts、…、n.ts
ffmpeg -i 挖掘机麦克斯第1集.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 1.ts
ffmpeg -i 挖掘机麦克斯第2集.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 2.ts
ffmpeg -i 挖掘机麦克斯第3集.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 3.ts

#再合成ts文件
ffmpeg -i "concat:1.ts|2.ts|3.ts" -acodec copy -vcodec copy -absf aac_adtstoasc 挖掘机麦克斯1-3集合并.mp4

批量生成转换合并命令

<?php
    /**
     * Created by PhpStorm.
     * User: Bruce Xie
     * Date: 2021-02-09
     * Time: 14:38
     */

    $mergedName = '小猪佩奇第一季52集合并';

    $concatArr = [];
    $cmdArr = [];
    for($i = 1; $i <= 52; $i++){
        $num = $i<10 ? '0'.$i : $i;
        $cmdArr[] = 'ffmpeg -i '.$num.'.小猪佩奇S01E'.$num.'.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb '.$num.'.ts';
        $concatArr[] = $num . '.ts';
    }
    $cmdStr = join(" &&\n",$cmdArr);
    $concatStr = join('|',$concatArr);
    $mergeCmd = 'ffmpeg -i "concat:'.$concatStr.'" -acodec copy -vcodec copy -absf aac_adtstoasc '.$mergedName.'.mp4';

    $contentToCopy = $cmdStr . " &&\n" . $mergeCmd;

    $clipboard = PHP_OS=='Darwin' ? 'pbcopy' : (PHP_OS=='WINNT' ? 'clip' : 'xclip -selection clipboard');
    $command = "echo '{$contentToCopy}' | {$clipboard}";
    shell_exec($command);
    echo 'Done! 请直接到终端中粘贴并回车运行!';

输出结果如下

ffmpeg -i 01.小猪佩奇S01E01.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 01.ts &&
ffmpeg -i 02.小猪佩奇S01E02.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 02.ts &&
ffmpeg -i 03.小猪佩奇S01E03.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 03.ts &&
ffmpeg -i 04.小猪佩奇S01E04.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 04.ts &&
ffmpeg -i 05.小猪佩奇S01E05.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 05.ts &&
ffmpeg -i 06.小猪佩奇S01E06.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 06.ts &&
ffmpeg -i 07.小猪佩奇S01E07.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 07.ts &&
ffmpeg -i 08.小猪佩奇S01E08.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 08.ts &&
ffmpeg -i 09.小猪佩奇S01E09.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 09.ts &&
ffmpeg -i 10.小猪佩奇S01E10.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 10.ts &&
ffmpeg -i 11.小猪佩奇S01E11.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 11.ts &&
ffmpeg -i 12.小猪佩奇S01E12.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 12.ts &&
ffmpeg -i 13.小猪佩奇S01E13.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 13.ts &&
ffmpeg -i 14.小猪佩奇S01E14.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 14.ts &&
ffmpeg -i 15.小猪佩奇S01E15.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 15.ts &&
ffmpeg -i 16.小猪佩奇S01E16.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 16.ts &&
ffmpeg -i 17.小猪佩奇S01E17.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 17.ts &&
ffmpeg -i 18.小猪佩奇S01E18.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 18.ts &&
ffmpeg -i 19.小猪佩奇S01E19.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 19.ts &&
ffmpeg -i 20.小猪佩奇S01E20.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 20.ts &&
ffmpeg -i 21.小猪佩奇S01E21.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 21.ts &&
ffmpeg -i 22.小猪佩奇S01E22.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 22.ts &&
ffmpeg -i 23.小猪佩奇S01E23.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 23.ts &&
ffmpeg -i 24.小猪佩奇S01E24.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 24.ts &&
ffmpeg -i 25.小猪佩奇S01E25.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 25.ts &&
ffmpeg -i 26.小猪佩奇S01E26.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 26.ts &&
ffmpeg -i 27.小猪佩奇S01E27.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 27.ts &&
ffmpeg -i 28.小猪佩奇S01E28.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 28.ts &&
ffmpeg -i 29.小猪佩奇S01E29.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 29.ts &&
ffmpeg -i 30.小猪佩奇S01E30.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 30.ts &&
ffmpeg -i 31.小猪佩奇S01E31.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 31.ts &&
ffmpeg -i 32.小猪佩奇S01E32.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 32.ts &&
ffmpeg -i 33.小猪佩奇S01E33.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 33.ts &&
ffmpeg -i 34.小猪佩奇S01E34.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 34.ts &&
ffmpeg -i 35.小猪佩奇S01E35.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 35.ts &&
ffmpeg -i 36.小猪佩奇S01E36.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 36.ts &&
ffmpeg -i 37.小猪佩奇S01E37.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 37.ts &&
ffmpeg -i 38.小猪佩奇S01E38.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 38.ts &&
ffmpeg -i 39.小猪佩奇S01E39.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 39.ts &&
ffmpeg -i 40.小猪佩奇S01E40.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 40.ts &&
ffmpeg -i 41.小猪佩奇S01E41.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 41.ts &&
ffmpeg -i 42.小猪佩奇S01E42.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 42.ts &&
ffmpeg -i 43.小猪佩奇S01E43.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 43.ts &&
ffmpeg -i 44.小猪佩奇S01E44.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 44.ts &&
ffmpeg -i 45.小猪佩奇S01E45.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 45.ts &&
ffmpeg -i 46.小猪佩奇S01E46.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 46.ts &&
ffmpeg -i 47.小猪佩奇S01E47.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 47.ts &&
ffmpeg -i 48.小猪佩奇S01E48.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 48.ts &&
ffmpeg -i 49.小猪佩奇S01E49.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 49.ts &&
ffmpeg -i 50.小猪佩奇S01E50.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 50.ts &&
ffmpeg -i 51.小猪佩奇S01E51.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 51.ts &&
ffmpeg -i 52.小猪佩奇S01E52.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 52.ts &&
ffmpeg -i "concat:01.ts|02.ts|03.ts|04.ts|05.ts|06.ts|07.ts|08.ts|09.ts|10.ts|11.ts|12.ts|13.ts|14.ts|15.ts|16.ts|17.ts|18.ts|19.ts|20.ts|21.ts|22.ts|23.ts|24.ts|25.ts|26.ts|27.ts|28.ts|29.ts|30.ts|31.ts|32.ts|33.ts|34.ts|35.ts|36.ts|37.ts|38.ts|39.ts|40.ts|41.ts|42.ts|43.ts|44.ts|45.ts|46.ts|47.ts|48.ts|49.ts|50.ts|51.ts|52.ts" -acodec copy -vcodec copy -absf aac_adtstoasc 小猪佩奇第一季52集合并.mp4
打赏
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x

扫码在手机查看
iPhone请用自带相机扫
安卓用UC/QQ浏览器扫

ffmpeg常用命令