使用ffmpeg合并flv视频

今天看到新浪的《亨说》这个栏目挺好的,就想着把他的视频下载下来,按照我一贯的做法,直接打开硕鼠下载就行了。结果,今天硕鼠不好用,合并时一直不成功,于是就自己手动合并了。

下载下来的视频如下:

budong@budongdeMacBook-Pro:~/Downloads/dowload_sina/download$ ll
total 791392
-rw-r--r--  1 budong  wheel  50444189  7  1 14:43 1.flv
-rw-r--r--  1 budong  wheel  49804207  7  1 14:43 2.flv
-rw-r--r--  1 budong  wheel  46795836  7  1 14:43 3.flv
-rw-r--r--  1 budong  wheel  45681559  7  1 14:43 4.flv
-rw-r--r--  1 budong  wheel  47641965  7  1 14:43 5.flv
-rw-r--r--  1 budong  wheel  43546455  7  1 14:43 6.flv
-rw-r--r--  1 budong  wheel  50463076  7  1 14:43 7.flv
-rw-r--r--  1 budong  wheel  56397258  7  1 14:43 8.flv
-rw-r--r--  1 budong  wheel  14394291  7  1 14:44 9.flv
-rw-r--r--  1 budong  wheel       117  7  9 10:50 inputs.txt

inputs.txt文件内容:

budong@budongdeMacBook-Pro:~/Downloads/dowload_sina/download$ cat inputs.txt
file '1.flv'
file '2.flv'
file '3.flv'
file '4.flv'
file '5.flv'
file '6.flv'
file '7.flv'
file '8.flv'
file '9.flv'

合并flv视频,生成一个大的视频output.flv:

budong@budongdeMacBook-Pro:~/Downloads/dowload_sina/download$ ffmpeg -f concat -i inputs.txt -c copy output.flv
ffmpeg version 2.3.3 Copyright (c) 2000-2014 the FFmpeg developers
  built on Sep 22 2014 11:13:44 with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid --enable-libfreetype --enable-libtheora --enable-libvorbis --enable-libvpx --enable-librtmp --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-aacenc --enable-libass --enable-ffplay --enable-libspeex --enable-libschroedinger --enable-libfdk-aac --enable-openssl --enable-libopus --enable-frei0r --enable-libcaca --enable-libquvi --enable-libvidstab --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags='-I/usr/local/Cellar/openjpeg/1.5.1_1/include/openjpeg-1.5 '
  libavutil      52. 92.100 / 52. 92.100
  libavcodec     55. 69.100 / 55. 69.100
  libavformat    55. 48.100 / 55. 48.100
  libavdevice    55. 13.102 / 55. 13.102
  libavfilter     4. 11.100 /  4. 11.100
  libavresample   1.  3.  0 /  1.  3.  0
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
[concat @ 0x7fb95900c200] Estimating duration from bitrate, this may be inaccurate
Input #0, concat, from 'inputs.txt':
  Duration: 00:00:00.02, start: 0.000000, bitrate: 42 kb/s
    Stream #0:0: Video: h264 (High), yuv420p, 1024x576 [SAR 1:1 DAR 16:9], 1025 kb/s, 25 fps, 25 tbr, 1k tbn, 50 tbc
    Stream #0:1: Audio: aac, 48000 Hz, stereo, fltp, 47 kb/s
Output #0, flv, to 'output.flv':
  Metadata:
    encoder         : Lavf55.48.100
    Stream #0:0: Video: h264 ([7][0][0][0] / 0x0007), yuv420p, 1024x576 [SAR 1:1 DAR 16:9], q=2-31, 1025 kb/s, 25 fps, 1k tbn, 1k tbc
    Stream #0:1: Audio: aac ([10][0][0][0] / 0x000A), 48000 Hz, stereo, 47 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=74236 fps=19088 q=-1.0 Lsize=  395660kB time=00:49:56.75 bitrate=1081.6kbits/s
video:374645kB audio:17254kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.959734%

output.flv就是合并后的视频,任务完成。

参考资料:

硕鼠:http://www.flvcd.com/

ffmpeg:https://trac.ffmpeg.org/wiki/Concatenate

http://superuser.com/questions/420363/how-to-concatenate-two-flv-files