3

Trying to loop an image to get a segmented HLS output.

ffmpeg -loop 1 -i image.png -vcodec libx264 -acodec aac -map 0 -f segment -segment_time 5 -segment_list /seg.m3u8  /200_%06d.ts

  Metadata:
    encoder         : Lavf54.26.101
    Stream #0:0: Video: h264, yuv444p, 1344x840, q=-1--1, 90k tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (png -> libx264)
Press [q] to stop, [?] for help
Failed to open bitstream filter h264_mp4toannexb for stream 0 with codec libx264: Invalid argument
[mpegts @ 0x7fe91a615600] H.264 bitstream malformed, no startcode found, use the h264_mp4toannexb bitstream filter (-bsf h264_mp4toannexb)
av_interleaved_write_frame(): Invalid argument

Adding in the filter does not seem to help.

llogan
  • 121,796
  • 28
  • 232
  • 243
hockey_dave
  • 524
  • 1
  • 7
  • 18

1 Answers1

7

As indicated (but not really explained) in the error message, there's an issue converting the h.264 video data to the MPEG2 transport stream. In the default h.264 container (MPEG4), things are length prefixed, whereas in MPEG2 transport streams, start codes are used. The mapping is described in an Annex of the h.264 spec, the mentioned Annex 2. Docs: http://git.videolan.org/?p=ffmpeg.git;a=blob;f=doc/bitstream_filters.texi

So to properly create the MPEG2 TS, you need to add -vbsf h264_mp4toannexb to the command line. You might also need to add the following arguments as well -flags -global_header as well. This is to make sure that some of the codec parameters are included in-band (within the transport stream).

vipw
  • 7,593
  • 4
  • 25
  • 48
  • Thank you for the very clear explanation. That gets by the error. I can write the ts file and ffplay can play it. However, jwplayer just plays a black screen. here is my m3u8 playlist for the HLS: – hockey_dave Sep 21 '12 at 19:40
  • #EXTM3U #EXT-X-PLAYLIST-TYPE:VOD #EXT-X-VERSION:3 #EXT-X-MEDIA-SEQUENCE:0 #EXT-X-ALLOWCACHE:1 #EXT-X-TARGETDURATION:2 #EXTINF:2.000000, dave.ts #EXT-X-ENDLIST – hockey_dave Sep 21 '12 at 19:41
  • 1
    Finally figured it out. I converted the png to a jpg and then did the conversion to video. – hockey_dave Sep 22 '12 at 20:58
  • thank you, especially for the `-flags -global_header` – gorodezkiy Jul 09 '15 at 13:10
  • I also have same problem , I want to create a ts segment from few images but I am unsure of how to write final ffmpeg command , can someone please help me here? – Shubham Nov 22 '19 at 09:53