自动执行 fmpeg 任务

自动执行 fmpeg 任务

我正在寻求帮助以在 OSX 上自动化 FFMPEG 工作流程。

我想要一个热文件夹,当我放下 .mp4 时,它会开始合并。它会在前面添加一张卡片,在后面添加一张卡片。前面的卡片与后面的卡片相同(但正面和背面不同)。

我曾使用过类似的东西成功输出 .mkv,但我不知道如何输出 .mp4

ffmpeg -i front.mp4 -i main.mp4 -i end.mp4 \
-filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0]2:a:0]concat=n=3:v=1:a=1[outv][outa]" \
-map "[outv]" -map "[outa]" output.mkv

LLogan 的结果日志

ffmpeg version 4.3 Copyright (c) 2000-2020 the FFmpeg developers
  built with Apple clang version 11.0.3 (clang-1103.0.32.62)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.3 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
  libavutil      56. 51.100 / 56. 51.100
  libavcodec     58. 91.100 / 58. 91.100
  libavformat    58. 45.100 / 58. 45.100
  libavdevice    58. 10.100 / 58. 10.100
  libavfilter     7. 85.100 /  7. 85.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  7.100 /  5.  7.100
  libswresample   3.  7.100 /  3.  7.100
  libpostproc    55.  7.100 / 55.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/Mark/FFMPEG/CARD/start.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.20.100
  Duration: 00:00:07.50, start: 0.000000, bitrate: 1737 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 1605 kb/s, 24 fps, 24 tbr, 12288 tbn, 48 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/Mark/FFMPEG/RAW/body.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 2020-04-12T01:12:58.000000Z
    encoder         : HandBrake 1.2.0 2018122200
  Duration: 00:43:51.96, start: 0.000000, bitrate: 2405 kb/s
    Stream #1:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 2264 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2020-04-12T01:12:58.000000Z
      handler_name    : VideoHandler
    Stream #1:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 132 kb/s (default)
    Metadata:
      creation_time   : 2020-04-12T01:12:58.000000Z
      handler_name    : SoundHandler
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/Mark/FFMPEG/CARD/end.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: isommp41mp42
    creation_time   : 2020-06-09T19:53:13.000000Z
  Duration: 00:00:28.00, start: 0.000000, bitrate: 2584 kb/s
    Stream #2:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 2479 kb/s, 23.96 fps, 23.98 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2020-06-09T19:53:13.000000Z
      handler_name    : Core Media Video
    Stream #2:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 96 kb/s (default)
    Metadata:
      creation_time   : 2020-06-09T19:53:13.000000Z
      handler_name    : Core Media Audio
At least one output file must be specified

答案1

我很难在单个命令行中“合并”MP4。但是,这种方法对我来说绝对有效。将其放入 shell 脚本中,例如merge.sh:

if [ $# -lt 2 ]
then
        printf "USAGE: $0 <mp4-files>\n"
        exit
fi

if [ -f merge.txt ]
then
    rm merge.txt    
fi

for file in "$@"
do
  if [ -f "$file" ]
  then
    echo "file '"`pwd`/"$file'" >> merge.txt
  fi
done

basename=`echo $1 | sed -e 's/\(.*\)\.[^.]*$/\1/'`
ffmpeg -f concat -safe 0 -i merge.txt -c copy "$basename.merged.mp4"

相关内容