FFmpeg串联可更改输入视频的持续时间和播放速度 [英] FFmpeg concatenation changes the duration and playback speed of the input videos

查看:148
本文介绍了FFmpeg串联可更改输入视频的持续时间和播放速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个使用FFmpeg concat多路分配器连接的输入视频:

I have two input videos that I am concatenating using the FFmpeg concat demuxer:

ffmpeg -f concat safe '0' -i /path/to/file.txt -c copy /path/to/output.mp4

file.txt包含两个文件路径,如下所示:

The file.txt contains the two file paths as follows:

ffconcat version 1.0

file /path/to/input/file1.mp4

file /path/to/input/file2.mp4

不幸的是,级联视频有两个问题:

Unfortunately, the concatenated video has two issues:

  • 第一个输入视频的持续时间为4秒.在输出视频中,最后一帧冻结了几秒钟,然后开始播放第二个输入视频.
  • 第二个输入视频的播放速度变慢,因此视频播放的时间不是7秒,而是大约14或15秒.

我尝试按照FFmpeg文档的指定,在.txt文件中指定每个视频的时长,但这似乎对输出没有影响.

I have tried specifying the duration of each video in the .txt file, as specified by the FFmpeg docs, but this doesn't seem to make a difference to the output.

我是FFmpeg的新手,因此非常感谢您的帮助!

I'm a bit of a newbie to FFmpeg, so any help is greatly appreciated!

编辑-FFprobe给出的每个输入视频的属性:

Edit - The properties of each input video as given by FFprobe:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'tmp/video/16382802.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.25.100
  Duration: 00:00:04.43, start: 0.000000, bitrate: 644 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 360x640, 640 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler


Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'tmp/video/16382805.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.25.100
  Duration: 00:00:07.31, start: 0.023220, bitrate: 836 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 360x640, 669 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, 5.1, fltp, 158 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

编辑2-重新包装视频时堆栈跟踪(音频丢失):

Edit 2 - Stack trace when rewrapping the video (audio is lost):

ffmpeg version 3.0.1 Copyright (c) 2000-2016 the FFmpeg developers
  built with Apple LLVM version 7.3.0 (clang-703.0.31)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.0.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --enable-libfreetype --enable-ffplay --enable-libfdk-aac --enable-frei0r --enable-nonfree --enable-vda
  libavutil      55. 17.103 / 55. 17.103
  libavcodec     57. 24.102 / 57. 24.102
  libavformat    57. 25.100 / 57. 25.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 31.100 /  6. 31.100
  libavresample   3.  0.  0 /  3.  0.  0
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'https://s3-eu-west-1.amazonaws.com/stories.snaplytics.io/fTYbaN78DBVEQI0js0ydhNw/d3ef9a13-454c-4015-8412-cbd890e70e24.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.25.100
  Duration: 00:00:07.31, start: 0.023220, bitrate: 746 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 360x640, 669 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 67 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Input #1, lavfi, from 'anullsrc':
  Duration: N/A, start: 0.000000, bitrate: 705 kb/s
    Stream #1:0: Audio: pcm_u8, 44100 Hz, stereo, u8, 705 kb/s
Output #0, mp4, to '/Users/barnabytaylor/Documents/fanbytes-dashboard/tmp/video/16382805.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.25.100
    Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 360x640, q=2-31, 669 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 30k tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1: Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz, 5.1, fltp, 341 kb/s
    Metadata:
      encoder         : Lavc57.24.102 aac
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (pcm_u8 (native) -> aac (native))
Press [q] to stop, [?] for help
frame=  219 fps= 57 q=-1.0 Lsize=   98706kB time=00:00:07.31 bitrate=110550.2kbits/s speed=1.91x    
video:598kB audio:6kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 16257.420898%
[aac @ 0x7ffbe2806e00] Qavg: 65536.000

推荐答案

第一个视频的时基较小(并且没有音轨).像这样重新包装,然后合并:

The first video has a smaller timebase (and no audio track). Rewrap it like this and then concat:

ffmpeg -i 16382802.mp4 -f lavfi -i anullsrc -c:v copy -video_track_timescale 30k -c:a aac -ac 6 -ar 44100 -shortest new.mp4

这篇关于FFmpeg串联可更改输入视频的持续时间和播放速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆