使用ffmpeg从mp4或flv中提取h264原始视频流会生成无效流

时间:2022-06-14 21:22:13

I'm trying to extract the video stream from an mp4 or flv h264 video (youtube video) using ffmpeg. The original video (test.flv) play without trouble with ffplay , ffprobe gives an error as follow:

我正在尝试使用ffmpeg从mp4或flv h264视频(youtube视频)中提取视频流。原始视频(test.flv)在使用ffplay时没有遇到任何问题,ffprobe给出了如下错误:

ffprobe version N-55515-gbbbd959 Copyright (c) 2007-2013 the FFmpeg developers
built on Aug 13 2013 18:06:32 with gcc 4.7.3 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-
amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --
enable-libxvid --enable-zlib
  libavutil      52. 42.100 / 52. 42.100
  libavcodec     55. 27.100 / 55. 27.100
  libavformat    55. 13.102 / 55. 13.102
  libavdevice    55.  3.100 / 55.  3.100
  libavfilter     3. 82.100 /  3. 82.100
  libswscale      2.  4.100 /  2.  4.100
  libswresample   0. 17.103 /  0. 17.103
  libpostproc    52.  3.100 / 52.  3.100
[flv @ 000000000031ea80] Stream discovered after head already parsed
Input #0, flv, from 'test.flv':
  Metadata:
    starttime       : 0
    totalduration   : 142
    totaldatarate   : 692
    bytelength      : 12286492
    canseekontime   : true
    sourcedata      : B42B95507HH1381414522145462
    purl            :
    pmsg            :
  Duration: 00:02:22.02, start: 0.000000, bitrate: 692 kb/s
    Stream #0:0: Video: h264 (Main), yuv420p, 640x268, 568 kb/s, 23.98 tbr, 1k t
bn, 47.95 tbc
    Stream #0:1: Audio: aac, 44100 Hz, stereo, fltp, 131 kb/s
    Stream #0:2: Data: none
Unsupported codec with id 0 for input stream 2

to get rid of the extra streams ( I only needs the video) I used the following ffmpeg command line:

摆脱额外的流(我只需要视频)我使用了以下ffmpeg命令行:

ffmpeg -i test.flv -map 0:0 -vcodec copy -an -f h264 test.h264

The new stream is unreadable by any player including ffplay and gives an error with ffprobe : test.h264: Invalid data found when processing inputq= 0B f=0/0

包括ffplay在内的任何播放器都无法读取新流,并且ffprobe出错:test.h264:处理inputq = 0B f = 0/0时发现无效数据

Any body have an idea about what am I doing wrong?

任何人都知道我做错了什么?

I also tried simpler youtube command line:

我也尝试过更简单的youtube命令行:

ffmpeg -i test.flv -vcodec copy -an test.h264

if I use another format (avi for example):

如果我使用其他格式(例如avi):

ffmpeg -i test.flv -vcodec copy -an test.avi

the output video is valid.

输出视频有效。

If I transcode the video

如果我对视频进行转码

ffmpeg -i test.flv -an test.h264

the output is also valid

输出也有效

Any suggestions?

有什么建议么?

1 个解决方案

#1


21  

To extract a raw video from an MP4 or FLV container you should specify the -bsf:v h264_mp4toannexb or -vbfs h264_mp4toannexb option.

要从MP4或FLV容器中提取原始视频,您应指定-bsf:v h264_mp4toannexb或-vbfs h264_mp4toannexb选项。

ffmpeg -i test.flv -vcodec copy -an -bsf:v h264_mp4toannexb test.h264

The raw stream without H264 Annex B / NAL cannot be decode by player. With that option ffmpeg perform a simple "mux" of each h264 sample in a NAL unit.

没有H264附件B / NAL的原始流不能被播放器解码。使用该选项,ffmpeg在NAL单元中执行每个h264样本的简单“mux”。

#1


21  

To extract a raw video from an MP4 or FLV container you should specify the -bsf:v h264_mp4toannexb or -vbfs h264_mp4toannexb option.

要从MP4或FLV容器中提取原始视频,您应指定-bsf:v h264_mp4toannexb或-vbfs h264_mp4toannexb选项。

ffmpeg -i test.flv -vcodec copy -an -bsf:v h264_mp4toannexb test.h264

The raw stream without H264 Annex B / NAL cannot be decode by player. With that option ffmpeg perform a simple "mux" of each h264 sample in a NAL unit.

没有H264附件B / NAL的原始流不能被播放器解码。使用该选项,ffmpeg在NAL单元中执行每个h264样本的简单“mux”。