[FFmpeg-user] Need to Convert MP4 (or MKV) with AAC *and* AC-3 Audio to Multi-Rendition HLS (each with *both* audio streams)
pehache
pehache.7 at gmail.com
Thu Sep 1 00:41:09 EEST 2022
Le 31/08/2022 à 00:51, Clay a écrit :
> Hi folks,
> Can you help me fix this ffmpeg script:
> The goal:
> Take in an mp4 (or mkv) with one video stream and TWO audio streams (one
> AAC/2ch and one AC-3/5.1ch)... and output four video renditions (1920,
> 1280, 720, 480) that all keep *both* audio streams.
> The input file is around 4mbps and I am attempting to clamp the video
> bitrates of the four renditions as close to these as possible: 4M/3M/2M/1M
> Due to HLS compatibility, the AAC must remain in the output file; and
> the AC-3 needs to remain as well.
> I thought this would be easy... just passing the audio through and
> copying it to each rendition output.. but this is kicking my butt.
> If you have a better way to achieve this, I am ***all ears***.
> Here is the code I have so far:
> #!/bin/bash
> ffmpeg -i ../InputFile-1920x804-24f.mp4 \
> -filter_complex "[0:v]split=4[v1][v2][v3][v4]; [v1]copy[v1out];
> [v2]scale=w=1280:h=536[v2out]; [v3]scale=w=720:h=300[v3out];
> [v4]scale=w=480:h=200[v4out]"\
> -map [v1out] -c:v:0 libx264 -x264-params -b:v:0 -maxrate:v:0 4M
> -minrate:v:0 4M -bufsize:v:0 4M -crf 17 -preset slower -g 48
> -sc_threshold 0 -keyint_min 48 \
> -map [v2out] -c:v:1 libx264 -x264-params -b:v:1 -maxrate:v:1 3M
> -minrate:v:1 3M -bufsize:v:1 3M -crf 17 -preset slower -g 48
> -sc_threshold 0 -keyint_min 48 \
> -map [v3out] -c:v:2 libx264 -x264-params -b:v:2 -maxrate:v:2 2M
> -minrate:v:2 2M -bufsize:v:2 2M -crf 17 -preset slower -g 48
> -sc_threshold 0 -keyint_min 48 \
> -map [v4out] -c:v:3 libx264 -x264-params -b:v:3 -maxrate:v:3 1M
> -minrate:v:3 1M -bufsize:v:3 1M -crf 17 -preset slower -g 48
> -sc_threshold 0 -keyint_min 48 \
> -map 0:a -c:a:0 \
> -map 0:a -c:a:1 \
> -map 0:a -c:a:2 \
> -map 0:a -c:a:3 \
> -f hls \
> -hls_time 2 \
> -hls_playlist_type vod \
> -hls_flags independent_segments \
> -hls_segment_type mpegts \
> -hls_segment_filename OutputFile_%v/data%02d.ts \
> -master_pl_name master.m3u8 \
> -var_stream_map "v:0,a:0 v:1,a:1 v:2,a:2 v:3,a:3"OutputFile_%v.m3u8
> This code breaks when I attempt to run it, giving the following error:
> [NULL @ 0x55f0357bbd40] Unable to find a suitable output format for '0:a'
> 0:a: Invalid argument
> I have tried many varieties of the audio stream mapping... 0:a, a:0,
> a:0:1.. etc.
> I am hoping one of you gurus here take pity on me and show me the way :-)
> _______________________________________________
Do you *really* need to achieve that with a single command?
Your lines
-map 0:a -c:a:1 \
should be (I think)
-map 0:a -c:a:1 copy \
More information about the ffmpeg-user
mailing list