如何串联两个flv文件?


15

我想通过Linux命令行工具连接两个flv文件(从Youtube.com下载)。
ffmpeg教程太复杂了,因此我尝试了本mencode教程
但是我得到一个空的输出。我不知道如何解决这个问题。

ffmpeg -i input_1.flv

ffmpeg version 0.8.1-4:0.8.1-0ubuntu1, Copyright (c) 2000-2011 the Libav developers
  built on Mar 22 2012 05:29:10 with gcc 4.6.3
This program is not developed anymore and is only provided for compatibility. Use avconv instead (see Changelog for the list of incompatible changes).
[flv @ 0x89faaa0] Estimating duration from bitrate, this may be inaccurate

Seems stream 0 codec frame rate differs from container frame rate: 59.94 (2997/50) -> 29.97 (30000/1001)
Input #0, flv, from 'input_1.flv':
  Metadata:
    starttime       : 0
    totalduration   : 173
    totaldatarate   : 457
    bytelength      : 9874241
    canseekontime   : true
    sourcedata      : B4A7D6704MH1334385311768958
    purl            : 
    pmsg            : 
  Duration: 00:02:52.83, start: 0.000000, bitrate: 459 kb/s
    Stream #0.0: Video: h264 (Main), yuv420p, 640x360 [PAR 1:1 DAR 16:9], 360 kb/s, 29.97 tbr, 1k tbn, 59.94 tbc
    Stream #0.1: Audio: aac, 44100 Hz, stereo, s16, 99 kb/s
At least one output file must be specified

ffmpeg -i input_2.flv

ffmpeg version 0.8.1-4:0.8.1-0ubuntu1, Copyright (c) 2000-2011 the Libav developers
  built on Mar 22 2012 05:29:10 with gcc 4.6.3
This program is not developed anymore and is only provided for compatibility. Use avconv instead (see Changelog for the list of incompatible changes).
[flv @ 0x85b7aa0] Estimating duration from bitrate, this may be inaccurate

Seems stream 0 codec frame rate differs from container frame rate: 59.94 (2997/50) -> 29.97 (30000/1001)
Input #0, flv, from 'input_2.flv':
  Metadata:
    starttime       : 0
    totalduration   : 488
    totaldatarate   : 254
    bytelength      : 15467674
    canseekontime   : true
    sourcedata      : BADC21903MH1334385484128583
    purl            : 
    pmsg            : 
  Duration: 00:08:07.54, start: 0.000000, bitrate: 250 kb/s
    Stream #0.0: Video: h264 (Main), yuv420p, 640x360 [PAR 1:1 DAR 16:9], 151 kb/s, 29.97 tbr, 1k tbn, 59.94 tbc
    Stream #0.1: Audio: aac, 44100 Hz, stereo, s16, 99 kb/s
At least one output file must be specified

mencoder -of lavf -oac copy -ovc copy -o output.flv input_1.flv input_2.flv

MEncoder svn r34540 (Ubuntu), built with gcc-4.6 (C) 2000-2012 MPlayer Team
success: format: 0  data: 0x0 - 0x96ab41
libavformat version 53.21.0 (external)
Mismatching header version 53.19.0
libavformat file format detected.
[flv @ 0xb6b09d80]Estimating duration from bitrate, this may be inaccurate
[lavf] stream 0: video (h264), -vid 0
[lavf] stream 1: audio (aac), -aid 0
VIDEO:  [H264]  640x360  0bpp  29.970 fps  360.0 kbps (43.9 kbyte/s)
[V] filefmt:44  fourcc:0x34363248  size:640x360  fps:29.970  ftime:=0.0334
** MUXER_LAVF *****************************************************************
REMEMBER: MEncoder's libavformat muxing is presently broken and can generate
INCORRECT files in the presence of B-frames. Moreover, due to bugs MPlayer
will play these INCORRECT files as if nothing were wrong!
*******************************************************************************
OK, exit.
videocodec: framecopy (640x360 0bpp fourcc=34363248)
Audio format 0x4134504d is incompatible with '-oac copy', please try '-oac pcm' instead or use '-fafmttag' to override it.

Exiting...

mencoder -of lavf -oac pcm -ovc copy -o output.flv input_1.flv input_2.flv

MEncoder svn r34540 (Ubuntu), built with gcc-4.6 (C) 2000-2012 MPlayer Team
success: format: 0  data: 0x0 - 0x96ab41
libavformat version 53.21.0 (external)
Mismatching header version 53.19.0
libavformat file format detected.
[flv @ 0xb6bb6d80]Estimating duration from bitrate, this may be inaccurate
[lavf] stream 0: video (h264), -vid 0
[lavf] stream 1: audio (aac), -aid 0
VIDEO:  [H264]  640x360  0bpp  29.970 fps  360.0 kbps (43.9 kbyte/s)
[V] filefmt:44  fourcc:0x34363248  size:640x360  fps:29.970  ftime:=0.0334
==========================================================================
Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
libavcodec version 53.35.0 (external)
Mismatching header version 53.32.2
AUDIO: 44100 Hz, 2 ch, s16le, 99.0 kbit/7.02% (ratio: 12376->176400)
Selected audio codec: [ffaac] afm: ffmpeg (FFmpeg AAC (MPEG-2/MPEG-4 Audio))
==========================================================================
** MUXER_LAVF *****************************************************************
REMEMBER: MEncoder's libavformat muxing is presently broken and can generate
INCORRECT files in the presence of B-frames. Moreover, due to bugs MPlayer
will play these INCORRECT files as if nothing were wrong!
*******************************************************************************
OK, exit.
videocodec: framecopy (640x360 0bpp fourcc=34363248)
VIDEO CODEC ID: 28
AUDIO CODEC ID: 2e, TAG: 0
Writing header...
[flv @ 0xb6bb6d80]Codec for stream 0 does not use global headers but container format requires global headers
[flv @ 0xb6bb6d80]Codec for stream 1 does not use global headers but container format requires global headers
[NULL @ 0xb6472380]codec not compatible with flv
Floating point exception (core dumped)

stat output.flv

  File: `output.flv'
  Size: 0           Blocks: 0          IO Block: 4096   regular empty file
Device: 700h/1792d  Inode: 1722857     Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/     kev)   Gid: ( 1000/     kev)
Access: 2012-05-04 10:44:45.153319669 +0800
Modify: 2012-05-04 10:44:45.153319669 +0800
Change: 2012-05-04 10:44:45.153319669 +0800
 Birth: -

mencoder -forceidx -of lavf -oac copy -ovc copy -o output.flv clip1.flv clip2.flv clip3.flv 来源
塞巴斯蒂安

Answers:


11

我个人会用ffmpeg的

康卡特解复用器

首先创建一个名为的文件inputs.txt,如下所示:

file 'input1.flv'
file 'input2.flv'

然后像这样使用ffmpeg:

ffmpeg -f concat -i inputs.txt -c copy output.mp4

(您可以使用output.flv,尽管MP4是通常更有用的格式)。从1.1开始,在ffmpeg版本上可以使用该解复用器。如果出于某些原因要坚持使用ffmpeg的过时版本,可以使用

Concat协议

这有点复杂。该FLV容器不会在文件级别支持级联,所以你需要REMUX到一个容器, -样的MPEG传输流。不幸的是,对于h.264视频和AAC音频,您需要应用几个比特流过滤器。

由于您使用的是Linux,因此可以使用命名管道。

mkfifo temp0 temp1

您需要在三个独立的终端窗口(或终端仿真器支持的ctrl+shift+t标签下,通常会打开一个新标签)中进行以下操作:

ffmpeg -i input0.flv -map 0 -c copy -f mpegts -bsf h264_mp4toannexb -y temp0

ffmpeg -i input1.flv -map 0 -c copy -f mpegts -bsf h264_mp4toannexb -y temp1

ffmpeg -f mpegts -i "concat:temp0|temp1" -c copy -absf aac_adtstoasc output.mp4

实际上,您可以在一个(看起来很复杂)命令行上运行所有这些代码:

ffmpeg -i input0.flv -map 0 -c copy -f mpegts -bsf h264_mp4toannexb -y temp0 2> /dev/null & \
ffmpeg -i input1.flv -map 0 -c copy -f mpegts -bsf h264_mp4toannexb -y temp1 2> /dev/null & \
ffmpeg -f mpegts -i "concat:temp0|temp1" -c copy -absf aac_adtstoasc output.mp4

确保output.mp4尚不存在,这将不起作用。如果有人在不支持命名管道的系统上阅读此文件,则他们必须使用:

ffmpeg -i input0.flv -map 0 -c copy -f mpegts -bsf h264_mp4toannexb temp0.ts
ffmpeg -i input1.flv -map 0 -c copy -f mpegts -bsf h264_mp4toannexb temp1.ts
ffmpeg -i "concat:temp0.ts|temp1.ts" -c copy -absf aac_adtstoasc output.mp4

这将创建一对名为temp0.ts和temp1.ts的中间文件,完成后可以安全地销毁它们。

请注意,这些说明适用于OP中指定的FLV文件,并且可能适用于Internet上的大多数现代FLV,因为它们几乎都使用h264视频和aac音频。对于其他编解码器,必须对这些说明进行一些调整。


很棒的答案!这是我设法合并FLV而无需重新编码视频的唯一方法。
neu242

1
@DaveJarvis您可能正在使用旧版本的ffmpeg(例如大多数主要Linux发行版的存储库中提供的版本)。从您的评论到我的另一个答案,我认为您使用的是Debian或Ubuntu(或衍生版本),甚至不包含真正的ffmpeg,而是来自libav团队的虚假且故意残缺的版本(由于某些讨厌)项目分叉政治)。从这里尝试使用ffmpeg的静态版本,或者按照ffmpeg Wiki说明进行编译。
evilsoup

2

您坚持使用FLV格式吗?你可以将它们转换成MPG或者一些其他格式(见),然后加入他们的行列(参见)。

或者您可以直接在flv文件上尝试加入方法。

编辑

阅读这个这个。它为MEncoder使用一些不同的参数。


谢谢。但是,它需要更多的磁盘空间来存储mpg文件。而且编码需要很长时间。我想合并两个flv文件,并修复标题。
凯夫(kev)2012年

好。链接中的join方法对flv文件有效吗?(“ cat”方法)。
tumchaaditya

1

我找到了一个python包:http : //pypi.python.org/pypi/vnc2flv/


flvcat.py

flvcat.py是用于FLV电影的简化编辑程序。它支持级联多个电影,剪切电影的帧大小,通过自动平移将电影重新采样为较小的大小等。语法:

flvcat.py [options] src1[:ranges1] src2[:ranges2] ... output 

对于每个电影文件,您可以通过指定其范围来剪辑要添加的电影部分。范围是逗号分隔的带连字符的毫秒列表。例如,

out.flv:10000-20000 

表示从电影out.flv(0:10-0:20)播放的10秒剪辑。还支持仅指定范围的一端:

out.flv:10000- 

表示除前10秒外的整个电影。省略范围时,将使用整个电影。

例子:

$ flvcat.py movie1.flv movie2.flv output.flv
(Concatenate movie1.flv and movie2.flv and save it as output.flv)

$ flvcat.py -W 640x480 movie1.flv output.flv
(Resize the movie1.flv with auto-panning with its window size 640x480 and save it as output.flv)

$ flvcat.py movie1.flv:15000-30000 output.flv
(Clip the part of movie1.flv from 0:15 to 0:30 and save it as output.flv)

$ flvcat.py movie1.flv:2500- output.flv
(Chop the first 2.5 seconds off and save it as output.flv)

选项:

-r fps
    Specifies the number of frames per second. (default: 15) 
-K keyframe
    Specifies the rate of key frames that is inserted in every this number of frames. (default: every 150 frames) 
-B blocksize
    Specifies the block size. (default: 32) 
-C wxh{+|-}x{+|-}y
    Specifies the clipping. (default: entire frame) 
-W wxh
    Specifies the window size for auto panning. Auto panning tracks the changes in the screen and tries to focus on the active part of the screen. This helps reducing the movie screen size. (default: no auto panning) 
-S speed
    Specifies the speed of auto panning. (default: 60 frames) 
-f
    Forces overwriting the output file. 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.