我正在尝试使用 ffmpeg 将输入视频从任何格式转码为具有 h.264 视频和 MP3 音频的 mp4,并使用 rtmp 将输出直接发送到 FMS 4.5,这样视频在转码后就可以立即流式传输。我的 ffmpeg 命令是:
ffmpeg -re -y -i /videos/to/be/transcoded/001 -c:v libx264 -b:v 480k -c:a libmp3lame -b:a 128k -f mp4 "rtmp://localhost/live/livestream"
输出:
ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
built on May 10 2013 15:14:14 with gcc 4.4.6 (GCC) 20120305 (Red Hat 4.4.6-4)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --enable-shared --enable-runtime-cpudetect --enable-gpl --enable-version3 --enable-postproc --enable-avfilter --enable-pthreads --enable-x11grab --enable-vdpau --disable-avisynth --enable-frei0r --enable-libopencv --enable-libdc1394 --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --disable-stripping
libavutil 52. 18.100 / 52. 18.100
libavcodec 54. 92.100 / 54. 92.100
libavformat 54. 63.104 / 54. 63.104
libavdevice 54. 3.103 / 54. 3.103
libavfilter 3. 42.103 / 3. 42.103
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/global/xcodes/1/transcodeTest/vidInput/001':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
creation_time : 2013-03-31 19:51:36
Duration: 00:01:19.18, start: 0.000000, bitrate: 708 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x360, 610 kb/s, 25 fps, 25 tbr, 50 tbn, 50 tbc
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 95 kb/s
Metadata:
creation_time : 2013-03-31 19:51:37
handler_name : IsoMedia File Produced by Google, 5-11-2011
[libx264 @ 0x1a82ec0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x1a82ec0] profile High, level 3.0
[libx264 @ 0x1a82ec0] 264 - core 130 - H.264/MPEG-4 AVC codec - Copyleft 2003-2013 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=24 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=480 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[mp4 @ 0x1a826c0] muxer does not support non seekable output
Output #0, mp4, to 'rtmp://172.30.3.20/live/livestream':
Metadata:
major_brand : mp42
minor_version : 0
compatible_brands: isommp42
encoder : Lavf54.63.104
Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 640x360, q=-1--1, 480 kb/s, 90k tbn, 25 tbc
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: mp3 (i[0][0][0] / 0x0069), 44100 Hz, stereo, fltp, 128 kb/s
Metadata:
creation_time : 2013-03-31 19:51:37
handler_name : IsoMedia File Produced by Google, 5-11-2011
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> libx264)
Stream #0:1 -> #0:1 (aac -> libmp3lame)
Could not write header for output file #0 (incorrect codec parameters ?): Operation not permitted
我不断收到的错误是“无法写入输出文件 #0 的标头(编解码器参数不正确?):操作不允许”。但如果我运行此相同命令并将 ffmpeg 输出到新视频文件,则不会收到此错误。
出了什么问题?我该如何避免这个错误?
答案1
我认为这问题是:
mp4 需要可搜索的输出,因为它在完成文件编码后会在文件开头写入一个 MOOV 原子。因此,这不是一种适合将数据提供给 rtmp 的格式。
请注意输出中的以下错误:
[mp4 @ 0x1a826c0] muxer does not support non seekable output
尝试使用 FLV 作为容器,而不是 MP4。在命令中替换-f mp4
为。-f flv