FFmpeg - 连接不知道格式的视频 [英] FFmpeg - Concatenate videos with not know format

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

问题描述

我正在开发一个应用程序.人们从其他地方通过手机上传视频.

在 PHP 中使用 CMS(它是开发应用程序的语言)我需要使用这些部分上传生成一个独特的视频.

通过 FFmpeg 我正在从命令行进行测试:

ffmpeg -i concat:IMG_1916.mp4|IMG_1917.mp4 -c copy videoLoop.mp4

当我运行这段代码时,它说:

<前>ffmpeg 版本 3.2.4 版权所有 (c) 2000-2017 FFmpeg 开发人员使用 Apple LLVM 版本 8.0.0 (clang-800.0.42.1) 构建配置:--prefix=/usr/local/Cellar/ffmpeg/3.2.4 --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-vdalibavutil 55. 34.101/55. 34.101libavcodec 57. 64.101/57. 64.101libav格式 57. 56.101/57. 56.101libavdevice 57. 1.100/57. 1.100libavfilter 6. 65.100/6. 65.100libavresample 3. 1. 0/3. 1. 0libswscale 4. 2.100/4. 2.100libswresample 2. 3.100/2. 3.100libpostproc 54. 1.100/54. 1.100[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8515000000] 发现重复的 MOOV Atom.跳过它输入 #0, mov,mp4,m4a,3gp,3g2,mj2, from 'concat:IMG_1916.mp4|IMG_1917.mp4':元数据:编码器:Lavf57.66.102主要品牌:isom次要版本:512兼容品牌:isomiso2avc1mp41持续时间:00:00:04.27,开始:0.000000,比特率:26792 kb/sStream #0:0(und): Video: h264 (Constrained Baseline) (avc1/0x31637661), yuv420p, 1920x1080, 11978 kb/s, 29.97 fps, 29.97 tbr, 30kt9tbn (default)元数据:handler_name : VideoHandler流 #0:1(und):音频:aac (LC) (mp4a/0x6134706D),44100 Hz,单声道,fltp,120 kb/s(默认)元数据:handler_name : SoundHandler输出 #0,mp4,到videoLoop.mp4":元数据:兼容品牌:isomiso2avc1mp41主要品牌:isom次要版本:512编码器:Lavf57.56.101Stream #0:0(und): Video: h264 (Constrained Baseline) ([33][0][0][0]/0x0021), yuv420p, 1920x1080, q=2-31, 11978 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 30k tbc (默认)元数据:handler_name : VideoHandler流 #0:1(und):音频:aac (LC) ([64][0][0][0]/0x0040),44100 Hz,单声道,120 kb/s(默认)元数据:handler_name : SoundHandler流映射:流 #0:0 -> #0:0(复制)流 #0:1 -> #0:1(复制)按 [q] 停止,按 [?] 寻求帮助帧= 127 fps=0.0 q=-1.0 Lsize= 6264kB 时间=00:00:04.22 比特率=12142.8kbits/s 速度= 376x视频:6196kB 音频:63kB 字幕:0kB 其他流:0kB 全局头:0kB 复用开销:0.076698%

此执行生成一个视频,但不与指定的 2 连接,仅与第一个连接.

为什么不加入 2?

要上传的视频格式非常不同,因此我无法定义编解码器.

解决方案

您必须在串联之前使所有输入相似,然后使用 concat 过滤器.一个粗略的例子(您当然必须根据自己的需要对其进行自定义):

ffmpeg -i input0 -i input1 -filter_complex "[0:v]fps=25,scale=1280:720,format=yuv420p,setsar=1,setpts=PTS-STARTPTS[v0];[1:v]fps=25,scale=1280:720,format=yuv420p,setsar=1,setpts=PTS-STARTPTS[v1];[0:a]aformat=channel_layouts=stereo:sample_rates=44100,asetpts=PTS-STARTPTS[a0];[1:a]aformat=channel_layouts=stereo:sample_rates=44100,asetpts=PTS-STARTPTS[a1];[v0][a0][v1][a1]concat=n=2:v=1:a=1[v][a]" -map "[v]" -map "[a]" -c:v libx264 -c:a aac -movflags +faststart output.mp4

I am developing an application. People upload videos from their mobile, from other places.

Using a CMS in PHP (it is the language with which the application is developed) I need to generate a unique video with these partial uploads.

Through FFmpeg I am doing tests, from the command line:

ffmpeg -i concat:IMG_1916.mp4|IMG_1917.mp4 -c copy videoLoop.mp4

This code when I run it says:

ffmpeg version 3.2.4 Copyright (c) 2000-2017 the FFmpeg developers

built with Apple LLVM version 8.0.0 (clang-800.0.42.1)

configuration: --prefix=/usr/local/Cellar/ffmpeg/3.2.4 --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.101 / 55. 34.101
    libavcodec     57. 64.101 / 57. 64.101
    libavformat    57. 56.101 / 57. 56.101
    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 @ 0x7f8515000000] Found duplicated MOOV Atom. Skipped it Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'concat:IMG_1916.mp4|IMG_1917.mp4':
Metadata:

    encoder         : Lavf57.66.102
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41

Duration: 00:00:04.27, start: 0.000000, bitrate: 26792 kb/s

    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080, 11978 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, 120 kb/s (default)
Metadata:

    handler_name    : SoundHandler

Output #0, mp4, to 'videoLoop.mp4':

Metadata:

    compatible_brands: isomiso2avc1mp41
    major_brand     : isom
    minor_version   : 512
    encoder         : Lavf57.56.101
    Stream #0:0(und): Video: h264 (Constrained Baseline) ([33][0][0][0] / 0x0021), yuv420p, 1920x1080, q=2-31, 11978 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 30k tbc (default)

Metadata:

    handler_name    : VideoHandler

Stream #0:1(und): Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz, mono, 120 kb/s (default)
Metadata:

    handler_name    : SoundHandler

Stream mapping:

    Stream #0:0 -> #0:0 (copy)
    Stream #0:1 -> #0:1 (copy)

Press [q] to stop, [?] for help
frame=  127 fps=0.0 q=-1.0 Lsize=    6264kB time=00:00:04.22 bitrate=12142.8kbits/s speed= 376x    
video:6196kB audio:63kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.076698%

This execution generates a video, but not concatenated with the 2 specified, only with the first one.

Why not join the 2?

The videos to upload, will be of very different formats so I can not define codec.

解决方案

You will have to make all inputs similar before concatenation, then use the concat filter. A rough example (you will of course have to customize it to your needs):

ffmpeg -i input0 -i input1 -filter_complex 
"[0:v]fps=25,scale=1280:720,format=yuv420p,setsar=1,setpts=PTS-STARTPTS[v0]; 
 [1:v]fps=25,scale=1280:720,format=yuv420p,setsar=1,setpts=PTS-STARTPTS[v1]; 
 [0:a]aformat=channel_layouts=stereo:sample_rates=44100,asetpts=PTS-STARTPTS[a0]; 
 [1:a]aformat=channel_layouts=stereo:sample_rates=44100,asetpts=PTS-STARTPTS[a1]; 
 [v0][a0][v1][a1]concat=n=2:v=1:a=1[v][a]" 
-map "[v]" -map "[a]" -c:v libx264 -c:a aac -movflags +faststart output.mp4

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

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