FFmpeg-不同时基的Concat视频 [英] FFmpeg - Concat videos with different time base

查看:271
本文介绍了FFmpeg-不同时基的Concat视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用concat多路分配器来concat视频,但是在使用一个视频时(下面的"video2.mp4")它不起作用. By不起作用,我的意思是在播放器上播放级联的视频之前,直到第二个视频部分开始播放为止(它再也无法读取视频了).它可以与concat过滤器一起使用.他们都是mp4影片,所以我认为是因为时间原因?我可以使用concat多路分配器连接其他视频,并且效果很好(即使使用不同的分辨率/比特率).仅在尝试连接"video2.mp4"时会发生这种情况.

I'm trying to concat videos with the concat demuxer, but it does not work when using one video ("video2.mp4" below). By does not work, I mean playing the concatenated video on a player will work until the second video part starts (it just cannot read the video anymore). It works with the concat filter though. They are both mp4 videos, so I think it's because of the time base ? I can concat other videos with the concat demuxer and it works fine (even with different resolutions/bitrate). It only happens when trying to concat "video2.mp4".

此外,我有很多这样的警告/错误,可能是当ffmpeg开始连接第二个视频时:

Also, I have a lot of warning/errors like this, probably when ffmpeg starts concatenating the 2nd video :

[mp4 @ 0x7f847a814800] Non-monotonous DTS in output stream 0:0; previous: 906906, current: 302359; changing to 906907. This may result in incorrect timestamps in the output file.

拥有最短连续时间的最佳方法是什么?如果确实存在问题,我是否真的需要使用concat过滤器还是可以更改"video1.mp4"的时基?

What would be the best way to have a minimum concat time ? Do I really need to use the concat filter or can I change the time base of "video1.mp4" if it's really the problem ?

任何帮助将不胜感激,谢谢!

Any help would be appreciated, thanks !

视频1:

ffprobe version 3.2.2 Copyright (c) 2007-2016 the FFmpeg developers
  built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.2.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
  libavutil      55. 34.100 / 55. 34.100
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.100 / 57. 56.100
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video1.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2016-08-17T22:50:35.000000Z
  Duration: 00:00:10.11, start: 0.000000, bitrate: 38018 kb/s
    Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1696x848, 37832 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2016-08-18T00:02:24.000000Z
      handler_name    : VideoHandle
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 189 kb/s (default)
    Metadata:
      creation_time   : 2016-08-18T00:02:24.000000Z
      handler_name    : SoundHandle 

视频2:

ffprobe version 3.2.2 Copyright (c) 2007-2016 the FFmpeg developers
  built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.2.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
  libavutil      55. 34.100 / 55. 34.100
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.100 / 57. 56.100
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video2.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2017-01-06T22:30:23.000000Z
  Duration: 00:00:08.19, start: 0.000000, bitrate: 101474 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 4096x2048 [SAR 1:1 DAR 2:1], 101549 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      creation_time   : 2017-01-06T22:30:23.000000Z
      handler_name    : ?Mainconcept Video Media Handler
      encoder         : AVC Coding
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 125 kb/s (default)
    Metadata:
      creation_time   : 2017-01-06T22:30:23.000000Z
      handler_name    : #Mainconcept MP4 Sound Media Handler 

FFMpeg命令:

ffmpeg -f concat -safe 0 -i concat.txt -c copy result.mp4

concat.txt:

concat.txt :

file '/path/to/video1.mp4'
file '/path/to/video2.mp4' 

命令结果:

ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers
  built with Apple LLVM version 8.0.0 (clang-800.0.42.1)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.2.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
  libavutil      55. 34.100 / 55. 34.100
  libavcodec     57. 64.101 / 57. 64.101
  libavformat    57. 56.100 / 57. 56.100
  libavdevice    57.  1.100 / 57.  1.100
  libavfilter     6. 65.100 /  6. 65.100
  libavresample   3.  1.  0 /  3.  1.  0
  libswscale      4.  2.100 /  4.  2.100
  libswresample   2.  3.100 /  2.  3.100
  libpostproc    54.  1.100 / 54.  1.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fbd8b808c00] Auto-inserting h264_mp4toannexb bitstream filter
Input #0, concat, from 'concat.txt':
  Duration: N/A, start: 0.000000, bitrate: 38021 kb/s
    Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 1696x848, 37832 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc
    Metadata:
      creation_time   : 2016-08-18T00:02:24.000000Z
      handler_name    : VideoHandle
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 189 kb/s
    Metadata:
      creation_time   : 2016-08-18T00:02:24.000000Z
      handler_name    : SoundHandle
Output #0, mp4, to 'result.mp4':
  Metadata:
    encoder         : Lavf57.56.100
    Stream #0:0(eng): Video: h264 (Baseline) ([33][0][0][0] / 0x0021), yuv420p, 1696x848, q=2-31, 37832 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 90k tbc
    Metadata:
      creation_time   : 2016-08-18T00:02:24.000000Z
      handler_name    : VideoHandle
    Stream #0:1(eng): Audio: aac (LC) ([64][0][0][0] / 0x0040), 48000 Hz, stereo, 189 kb/s
    Metadata:
      creation_time   : 2016-08-18T00:02:24.000000Z
      handler_name    : SoundHandle
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy) 
Press [q] to stop, [?] for help
frame=  112 fps=0.0 q=-1.0 size=   12701kB time=00:00:03.70 bitrate=28092.2kbits/s speed= 7.4x
frame=  151 fps=151 q=-1.0 size=   18853kB time=00:00:05.00 bitrate=30857.5kbits/s speed=   5x
frame=  224 fps=149 q=-1.0 size=   30042kB time=00:00:07.44 bitrate=33074.8kbits/s speed=4.95x
frame=  268 fps=134 q=-1.0 size=   36596kB time=00:00:08.90 bitrate=33650.8kbits/s speed=4.44x
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fbd8a808000] Auto-inserting h264_mp4toannexb bitstream filter.9x 
[mp4 @ 0xb545d000] Non-monotonous DTS in output stream 0:1; previous: 484352, current: 445939; changing to 484353. This may result in incorrect timestamps in the output file.
[concat @ 0xb545c400] DTS 304057 < 906906 out of order
[mp4 @ 0xb545d000] Non-monotonous DTS in output stream 0:0; previous: 906906, current: 304057; changing to 906907. This may result in incorrect timestamps in the output file.
[mp4 @ 0xb545d000] Non-monotonous DTS in output stream 0:1; previous: 484353, current: 446963; changing to 484354. This may result in incorrect timestamps in the output file.
...
... like 100 DTS errors ...
...
[mp4 @ 0xb545d000] Non-monotonous DTS in output stream 0:0; previous: 907150, current: 548301; changing to 907151. This may result in incorrect timestamps in the output file.
frame=  548 fps=169 q=-1.0 Lsize=  148399kB time=00:00:18.28 bitrate=66493.7kbits/s speed=5.64x
video:148027kB audio:359kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.008622%

提前谢谢!

推荐答案

video2.mp4中的H.264比特流有些时髦

There's something funky about the H.264 bitstream in video2.mp4

下面的步骤(一次执行)将为我解决此问题,并且生成的concat可以在ffplay,Potplayer,VLC,WMP,Chrome和Firefox中正常运行.

The steps below (to be applied once) resolves it for me and the resulting concat plays fine with ffplay, Potplayer, VLC, WMP, Chrome and Firefox.

#1 转换视频2以匹配视频1

#1 Convert video 2 to match video 1

ffmpeg -i video2.mp4 -vf scale=1696x848 -profile:v baseline -c:a copy v2.mp4

#2 提取到原始比特流

ffmpeg -i v2.mp4 -c copy -f h264 v2.h264

#3 混合到新容器中

ffmpeg -i v2.h264 -i v2.mp4 -c copy -video_track_timescale 90000 -map 0 -map 1:a v2-ok.mp4

现在,您可以将v2-ok.mp4与video1.mp4连接了

Now, you can concat v2-ok.mp4 with video1.mp4

这篇关于FFmpeg-不同时基的Concat视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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