Opened 10 years ago

Closed 3 years ago

#3811 closed defect (invalid)

Misleading error when segmenting H.264 bitstream to MPEG-TS

Reported by: slhck Owned by:
Priority: normal Component: undetermined
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

I was trying to segment an existing H.264/MP4 file into TS segments:

ffmpeg -y -i tmp/tmpPass2.mp4 -c:v libx264 -acodec copy -map 0 -f
segment -bsf h264_mp4toannexb -segment_time 5 -segment_format mpegts
./tsSegmentsDisplay/SRC04_Q1_%05d.ts
ffmpeg version N-64919-ga613257 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jul 23 2014 00:35:22 with gcc 4.8.3 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads
--enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r
--enable-gnutls --enable-iconv --enable-libass --enable-libbluray
--enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme
--enable-libgsm --enable-libilbc --enable-libmodplug
--enable-libmp3lame --enable-libopencore-amrnb
--enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus
--enable-librtmp --enable-libschroedinger --enable-libsoxr
--enable-libspeex --enable-libtheora --enable-libtwolame
--enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc
--enable-libvorbis --enable-libvpx --enable-libwavpack
--enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs
--enable-libxvid --enable-decklink --enable-zlib
  libavutil      52. 92.101 / 52. 92.101
  libavcodec     55. 69.100 / 55. 69.100
  libavformat    55. 48.101 / 55. 48.101
  libavdevice    55. 13.102 / 55. 13.102
  libavfilter     4. 11.102 /  4. 11.102
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'tmp/tmpPass2.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.33.100
  Duration: 00:00:56.66, start: 0.161134, bitrate: 8528 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p,
1920x1080 [SAR 1:1 DAR 16:9], 8484 kb/s, 24 fps, 24 tbr, 12288 tbn, 48
tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz,
stereo, fltp, 64 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
[libx264 @ 0000000004db87a0] using SAR=1/1
[libx264 @ 0000000004db87a0] using cpu capabilities: MMX2 SSE2Fast
SSSE3 SSE4.2 AVX AVX2 FMA3 LZCNT BMI2
[libx264 @ 0000000004db87a0] profile High, level 4.0
[libx264 @ 0000000004db87a0] 264 - core 142 r2431 ac76440 -
H.264/MPEG-4 AVC codec - Copyleft 2003-2014 -
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=12
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=24 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf
mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40
aq=1:1.00
[mpegts @ 0000000006f42440] Using AVStream.codec.time_base as a
timebase hint to the muxer is deprecated. Set AVStream.time_base
instead.
    Last message repeated 1 times
[adts @ 0000000006f567e0] Using AVStream.codec.time_base as a timebase
hint to the muxer is deprecated. Set AVStream.time_base instead.
Output #0, segment, to './tsSegmentsDisplay/SRC04_Q1_%05d.ts':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf55.48.101
    Stream #0:0(und): Video: h264 (libx264), yuv420p, 1920x1080 [SAR
1:1 DAR 16:9], q=-1--1, 24 fps, 24 tbn, 24 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc55.69.100 libx264
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz,
stereo, 64 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[libx264 @ 0000000004db8340] Packet header is not contained in global
extradata, corrupted stream or invalid MP4/AVCC bitstream
Failed to open bitstream filter h264_mp4toannexb for stream 0 with
codec libx264: Invalid argument
[mpegts @ 0000000006f42440] H.264 bitstream malformed, no startcode
found, use the h264_mp4toannexb bitstream filter (-bsf
h264_mp4toannexb)
av_interleaved_write_frame(): Invalid argument
frame=   57 fps= 33 q=-1.0 Lsize=N/A time=00:00:02.69 bitrate=N/A dup=4 drop=0
video:201kB audio:21kB subtitle:0kB other streams:0kB global
headers:0kB muxing overhead: unknown
[libx264 @ 0000000004db87a0] frame I:1     Avg QP:19.95  size:204698
[libx264 @ 0000000004db87a0] frame P:19    Avg QP:21.95  size: 42957
[libx264 @ 0000000004db87a0] frame B:37    Avg QP:26.12  size:  9696
[libx264 @ 0000000004db87a0] consecutive B-frames:  3.5%  7.0% 68.4% 21.1%
[libx264 @ 0000000004db87a0] mb I  I16..4: 36.5% 18.1% 45.4%
[libx264 @ 0000000004db87a0] mb P  I16..4:  7.0%  6.7%  1.7%  P16..4:
32.9% 13.2%  7.7%  0.0%  0.0%    skip:30.7%
[libx264 @ 0000000004db87a0] mb B  I16..4:  0.9%  1.2%  0.1%  B16..8:
38.4%  3.9%  0.5%  direct: 1.3%  skip:53.7%  L0:46.9% L1:44.3% BI:
8.9%
[libx264 @ 0000000004db87a0] 8x8 transform intra:40.2% inter:58.4%
[libx264 @ 0000000004db87a0] coded y,uvDC,uvAC intra: 33.5% 48.0%
23.3% inter: 11.4% 13.0% 1.2%
[libx264 @ 0000000004db87a0] i16 v,h,dc,p: 33% 29% 19% 19%
[libx264 @ 0000000004db87a0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 40% 19%
36%  1%  1%  1%  1%  1%  1%
[libx264 @ 0000000004db87a0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 42% 34%
11%  2%  2%  2%  3%  2%  3%
[libx264 @ 0000000004db87a0] i8c dc,h,v,p: 48% 23% 25%  4%
[libx264 @ 0000000004db87a0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0000000004db87a0] ref P L0: 76.1% 14.4%  6.4%  3.1%
[libx264 @ 0000000004db87a0] ref B L0: 86.1% 11.9%  2.0%
[libx264 @ 0000000004db87a0] ref B L1: 86.7% 13.3%
[libx264 @ 0000000004db87a0] kb/s:4647.21
Conversion failed!

It tells me:

[libx264 @ 0000000004db8340] Packet header is not contained in global
extradata, corrupted stream or invalid MP4/AVCC bitstream
Failed to open bitstream filter h264_mp4toannexb for stream 0 with
codec libx264: Invalid argument
[mpegts @ 0000000006f42440] H.264 bitstream malformed, no startcode
found, use the h264_mp4toannexb bitstream filter (-bsf
h264_mp4toannexb)

But I'm already using said bitstream filter, which it can't open.

In this case, the real solution would've been to use the ssegment muxer instead of segment, but this is absolutely not obvious from the error messages.

There should be a hint to use another muxer when using .ts segments and H.264 bitstreams. The current error messages are misleading.

Change History (13)

comment:1 by Hendrik, 10 years ago

You're re-encoding the video, you don't need the bitstream filter at all.
The encoding step will already output the video as you need it for TS.

in reply to:  1 comment:2 by slhck, 10 years ago

Replying to heleppkes:

You're re-encoding the video, you don't need the bitstream filter at all.
The encoding step will already output the video as you need it for TS.

True, I don't need the filter, but If I leave it out, I get

$ ffmpeg -i input.mp4 -c:v libx264 -an -f segment -segment_format mpegts -map 0 test%05d.ts
...
[mpegts @ 0x25ded20] H.264 bitstream malformed, no startcode found, use the h264_mp4toannexb bitstream filter (-bsf h264_mp4toannexb)

Which is the point of this bug report: The error message is misleading. It's telling me to use the filter when I don't need to; and if I use the filter it's still telling me to use it.

The actual solution would be to tell me to use the right muxer.


comment:3 by Carl Eugen Hoyos, 10 years ago

$ ffmpeg -i input -flags -global_header -vcodec libx264 -map 0 -f segment -segment_time 5 -segment_format mpegts out%5d.ts

Please note that it is completely impossible to understand your original report.

comment:4 by Carl Eugen Hoyos, 10 years ago

Summary: Misleading error when segmenting H.264 bitstream to MPEG-TS with wrong segment muxerMisleading error when segmenting H.264 bitstream to MPEG-TS

comment:5 by slhck, 10 years ago

If you have suggestions on how to change it, please let me know.

I said that the error message is misleading because:

  • I already use the bitstream filter
  • It tells me to use the bitstream filter

My proposal is:

  • Don't tell me to use the bistream filter if I'm already using it
  • Tell me to use the ssegment muxer if that's what solves the issue

comment:6 by Hendrik, 10 years ago

The individual components don't know about each other, which is part of its extreme flexibility. It just mentions the most common cases in the error.

As such, the mpegts muxer doesn't know that its running in the segment context.

It should probably be documented that for mpegts you want the ssegment muxer, if its not documented properly somewhere already and you just didn't find that.

in reply to:  6 ; comment:7 by slhck, 10 years ago

Replying to heleppkes:

It should probably be documented that for mpegts you want the ssegment muxer, if its not documented properly somewhere already and you just didn't find that.

The documentation mentions that:

stream_segment is a variant of the muxer used to write to streaming output formats, i.e. which do not require global headers, and is recommended for outputting e.g. to MPEG transport stream segments.

Perhaps if we'd replace "recommended" with "necessary", it'd be more obvious that you need the ssegment muxer.

It honestly took me a while to find the source of the error although I think I'm quite experienced with the tool.

in reply to:  6 comment:8 by Carl Eugen Hoyos, 10 years ago

Replying to heleppkes:

It should probably be documented that for mpegts you want the ssegment muxer, if its not documented properly somewhere already and you just didn't find that.

It is documented but it took me some time to find it (the same problem was reported last week on the user mailing list but I only found out today).

in reply to:  7 comment:9 by Carl Eugen Hoyos, 10 years ago

Replying to slhck:

stream_segment is a variant of the muxer used to write to streaming output formats, i.e. which do not require global headers, and is recommended for outputting e.g. to MPEG transport stream segments.

Perhaps if we'd replace "recommended" with "necessary",

But it is not necessary, see my comment:3 ...

in reply to:  5 comment:10 by Carl Eugen Hoyos, 10 years ago

Replying to slhck:

If you have suggestions on how to change it, please let me know.

As we apparently all agree, the problematic command line plus error message is not the one in the original report (you are specifying an option there that simply cannot work) but the one in comment:2 (the one without console output).

comment:11 by slhck, 10 years ago

The original command is problematic, because how should I know that (frmo the original report)

ffmpeg -i input.mp4 -c:v libx264 -map 0 -f
segment -bsf h264_mp4toannexb -segment_time 5 -segment_format mpegts
test%05d.ts

does not work, when

ffmpeg -i input.mp4 -c:v libx264 -an -f segment -segment_format mpegts -map 0 test%05d.ts

explicitly tells me to use -bsf h264_mp4toannexb?

Either way, obviously there are confusing messages, so how could they be improved to have users figure out what needs to be done?

Maybe

Packet header is not contained in global extradata, try using -flags global_extradata

would work?

in reply to:  11 comment:12 by Carl Eugen Hoyos, 10 years ago

Replying to slhck:

Packet header is not contained in global extradata, try using -flags global_extradata

would work?

I (strongly) object being the one who has to answer the million questions then.

comment:13 by Balling, 3 years ago

Resolution: invalid
Status: newclosed

Just -c copy the video and audio.

Note: See TracTickets for help on using tickets.