kkroening / ffmpeg-python

Python bindings for FFmpeg - with complex filtering support
Apache License 2.0
9.91k stars 883 forks source link

How to convert mp4 to hls? #154

Open LambertKong opened 5 years ago

LambertKong commented 5 years ago

I want to convert a mp4 file to hls by using the following command:

ffmpeg -i input.mp4 -c:v libx264 -c:a aac -strict -2 -f hls -hls_list_size 0 -hls_time 5 output.m3u8

How to use it in ffmpeg-python?

anurag2090 commented 5 years ago

This is how you can get this done.

input_stream = ffmpeg.input('input.mp4', f='mp4')
output_stream = ffmpeg.output(input_stream, 'output.m3u8', format='hls', start_number=0, hls_time=5, hls_list_size=0)
ffmpeg.run(output_stream)

That worked for me. Idea is to pass those args in ffmpeg.output function as kwargs. I didn't get time to try it with audio and video codec options, as in your command, but I think that also should work.

JollyGoal commented 4 years ago

This worked for me: ffmpeg.input('input.mp4').output('output.m3u8', format='hls', start_number=0, hls_time=10, hls_list_size=0).run() But I am wondering if there is a way to choose the names of the segments (with that code segments names are output1.ts, output2.ts etc.)

suyx commented 3 years ago

Could you please tell me how i can add hls_list_size and hls_time to hls.output on Django Python?

sannjayy commented 3 years ago

With Encription

ffmpeg -y \ -i sample.mov \ -hls_time 9 \ -hls_key_info_file enc.keyinfo -hls_playlist_type vod \ -hls_segment_filename "fileSequence%d.ts" \ prog_index.m3u8

adding something like this to your FFmpeg command should work:

ffmpeg -i fighter.mp4 -hls_time 10 -hls_key_info_file file.keyinfo stream.m3u8