ffmpeg:使用一个命令

时间:2018-03-14 20:57:01

标签: bash ffmpeg

我有script自动编码和连接一系列输入视频文件。 我试图在一个命令中进行编码和连接。

目前它不起作用,导致最终视频输出中出现巨大的空暂停。

我想用concat demux而不是concat协议来获得结果,因为在脚本中自动化要困难得多

您知道是否可以使用concat demux归档此结果? 非常感谢!

的Massimo

ENCODE / CONCAT 1080p

for f in ./*.mp4; do echo "file '$f'" >> list.txt; done

ffmpeg -f concat -safe 0 -y -i list.txt -i ../logo/logo.png -c:a aac -b:a 384k -ar 48000 -ac 2 -af aresample=async=1000 -c:v libx264 -x264opts keyint=50:min-keyint=50:no-scenecut -bf 0 -r 25 -b:v 4800k -maxrate 4800k -bufsize 3000k -profile:v main -crf 22 -filter_complex "[0:v][1:v]overlay=main_w-overlay_w-10:10,scale=1920:1080,setsar=1" ../buffer/1080set.mp4

似乎在低帧速率下添加了长暂停:

  

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fb03f05e600]自动插入h264_mp4toannexb比特流过滤器

     

frame = 9745 fps = 13 q = 27.0 size = 186368kB time = 00:18:52.56 bitrate = 1348.0kbits

     

帧= 9745 fps = 13 q = 27.0大小= 186368kB时间= 00:18:56.57比特率= 1343.3kbits /

     

帧= 9745 fps = 13 q = 27.0大小= 186368kB时间= 00:19:00.65比特率= 1338.5kbits /

     

帧= 9745 fps = 13 q = 27.0大小= 186368kB时间= 00:19:02.29比特率= 1336.5kbits /

     

超过1000帧重复

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '1.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 2016-02-27T22:25:49.000000Z
    encoder         : HandBrake 0.10.5 2016021100
  Duration: 00:06:29.87, start: 0.000000, bitrate: 3447 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 768x432, 3282 kb/s, 25 fps, 25 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2016-02-27T22:25:49.000000Z
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 159 kb/s (default)
    Metadata:
      creation_time   : 2016-02-27T22:25:49.000000Z
      handler_name    : Stereo

Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '2.mp4':
  Metadata:
    major_brand     : M4V 
    minor_version   : 1
    compatible_brands: M4V mp42isom
    creation_time   : 2016-02-27T18:52:37.000000Z
  Duration: 00:07:16.93, start: 0.000000, bitrate: 1184 kb/s
    Stream #1:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 768x432, 991 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2016-02-27T18:52:37.000000Z
      handler_name    : Mainconcept MP4 Video Media Handler
      encoder         : AVC Coding
    Stream #1:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 189 kb/s (default)
    Metadata:
      creation_time   : 2016-02-27T18:52:37.000000Z
      handler_name    : Mainconcept MP4 Sound Media Handler

Input #2, mov,mp4,m4a,3gp,3g2,mj2, from '3.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2017-06-27T17:58:17.000000Z
  Duration: 00:05:05.05, start: 0.000000, bitrate: 2622 kb/s
    Stream #2:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 768x432, 2301 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2017-06-27T17:58:17.000000Z
      handler_name    : Alias Data Handler
      encoder         : AVC Coding
    Stream #2:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
    Metadata:
      creation_time   : 2017-06-27T17:58:17.000000Z
      handler_name    : Alias Data Handler

Input #3, mov,mp4,m4a,3gp,3g2,mj2, from '4.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2017-06-27T17:53:32.000000Z
  Duration: 00:06:47.36, start: 0.000000, bitrate: 3144 kb/s
    Stream #3:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 768x432, 2819 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2017-06-27T17:53:32.000000Z
      handler_name    : Alias Data Handler
      encoder         : AVC Coding
    Stream #3:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
    Metadata:
      creation_time   : 2017-06-27T17:53:32.000000Z
      handler_name    : Alias Data Handler

1 个答案:

答案 0 :(得分:1)

concat demxuer

concat demuxer需要所有输入具有相同的格式,流的数量,流的类型,流的顺序(或使用exact_stream_id),时基,帧速率,音频采样率,音频通道布局和它也建议具有相同的宽度和高度。

在您的情况下,第一个输入的时基(tbn)与其余输入不同。您可以预处理此输入以使其符合其他输入:

ffmpeg -i 1.mp4 -c copy -video_track_timescale 25k 1_reset.mp4

然后使用concat demuxer运行命令。

concat过滤器

因为您无论如何都要重新编码,所以使用concat过滤器可能更容易。这允许您使用各种过滤器来符合每个输入,然后在一个命令中进行连接。此网站上有several examples这样的用途。