user2138489
user2138489

Reputation: 75

convert flv video file to m3u8 format with h264 and aac codec in ffmpeg

I want to convert a flv video file to a m3u8 container using AAC and H264 encoding in FFmpeg version 0.7.15. Can anyone help me on this?

I used this command to convert to the m3u8 format, but it throws an error:

cmd: ffmpeg -i sample.flv -b 1104k -s 320x240 -vcodec libx264 -ab 32 -ar 24000 -acodec libfaac final_video.m3u8

Error:

ffmpeg version 0.7.15, Copyright (c) 2000-2013 the FFmpeg developers
  built on Feb 22 2013 07:22:31 with gcc 4.4.5
  configuration: --enable-libdc1394 --prefix=/usr --extra-cflags='-Wall -g ' --cc='ccache cc' --enable-shared --enable-libmp3lame --enable-gpl --enable-libvorbis --enable-pthreads --enable-libfaac --enable-libxvid --enable-postproc --enable-x11grab --enable-libgsm --enable-libtheora --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libx264 --enable-libspeex --enable-nonfree --disable-stripping --enable-avfilter --enable-libdirac --disable-decoder=libdirac --enable-libfreetype --enable-libschroedinger --disable-encoder=libschroedinger --enable-version3 --enable-libopenjpeg --enable-libvpx --enable-librtmp --extra-libs=-lgcrypt --disable-altivec --disable-armv5te --disable-armv6 --disable-vis
  libavutil    50. 43. 0 / 50. 43. 0
  libavcodec   52.123. 0 / 52.123. 0
  libavformat  52.111. 0 / 52.111. 0
  libavdevice  52.  5. 0 / 52.  5. 0
  libavfilter   1. 80. 0 /  1. 80. 0
  libswscale    0. 14. 1 /  0. 14. 1
  libpostproc  51.  2. 0 / 51.  2. 0
[libspeex @ 0x93e6c60] Missing Speex header, assuming defaults.
[flv @ 0x93e25e0] Estimating duration from bitrate, this may be inaccurate

Seems stream 0 codec frame rate differs from container frame rate: 60.00 (60/1) -> 30.00 (60/2)
Input #0, flv, from 'sample.flv':
  Metadata:
    duration        : 60
    creationdate    : Wed Apr 10 17:13:05
  Duration: 00:01:00.05, start: 0.000000, bitrate: N/A
    Stream #0.0: Video: h264 (Main), yuv420p, 320x240 [PAR 1:1 DAR 4:3], 30 tbr, 1k tbn, 60 tbc
    Stream #0.1: Audio: libspeex, 16000 Hz, 1 channels, s16
WARNING: The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s
[NULL @ 0x93e3840] Unable to find a suitable output format for 'final_video.m3u8'
final_video.m3u8: Invalid data found when processing input

Upvotes: 0

Views: 6523

Answers (3)

Michael Kaufman
Michael Kaufman

Reputation: 442

I made a medium post on this here Learn more about ffmpeg options here

ffmpeg -i demo.flv -b:v 1M -g 60 -hls_time 2 -hls_list_size 0 -hls_segment_size 500000 output.m3u8

Let’s breakdown the command (It does a lot! 😮 )

We have as -i input the demo.flv file with a video -b:v bitrate of 1M and -g set the group of pictures to 60 (default 12), -hls_time of 2 creates a playlist file and makes one or more segment files in time slices of 2.

Then, set hls_list_size to 0 so the list file will contain all the segments and return only one playlist.m3u8, and finally hls_segment_size of 62.5kB max (Picks minimum of segment size or segment time).

stream-video-with-go

Upvotes: 1

Ed999
Ed999

Reputation: 3081

The format .M3U8 is not a valid output format.

Only a valid container format, such as .mp4 or .mkv, can be used to hold (i.e. "wrap around") the video and audio streams coming from the .flv file. But .m3u8 is a playlist format, which can only validly contain text.

You cannot convert from a video format, such as .flv, to a non-video format. It is like trying to wrap a video stream in a .pdf or .doc container: it won't work. So ffmpeg rightly throws a fit if you try to do it.

Upvotes: 0

slhck
slhck

Reputation: 38691

Your FFmpeg version is too old—only recent FFmpeg has a segment muxer built in. Refer to the documentation for more. Download a recent static build, or compile it from source.

For example:

ffmpeg -i sample.flv -c:v libx264 -b:v 1104K -c:a libfaac -b:a 32K -ar 24000 -f segment -segment_list playlist.m3u8 -segment_list_flags +live -segment_time 10 out%03d.mkv

Note that using -ab 32 means 32 Bit/s. If you want Kilobits, use 32K instead, and you might want to use the more unambiguous -b:a.

Upvotes: 2

Related Questions