我想使用 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: -
答案1
我个人会用 ffmpeg 的
Concat 解复用器
首先创建一个名为的文件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 容器不支持文件级别的连接,因此您需要重新混合到做- 就像 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 文件,也可能适用于互联网上大多数现代 FLV,因为它们几乎普遍使用 h264 视频和 aac 音频。对于其他编解码器,这些说明必须稍作调整。
答案2
答案3
我找到了一个python包:http://pypi.python.org/pypi/vnc2flv/
猫
flvcat.py
是一款简单的 FLV 电影编辑程序。它支持连接多部电影、剪辑电影的帧大小、使用自动平移将电影重新采样为较小的尺寸等。语法:
flvcat.py [options] src1[:ranges1] src2[:ranges2] ... output
对于每个电影文件,您可以通过指定其范围来剪辑要添加的电影部分。范围是以逗号分隔的带连字符的毫秒列表。例如,
out.flv:10000-20000
表示来自影片 out.flv 的 10 秒剪辑(0:10-0:20)。还支持仅指定范围的一端:
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.