ffmpeg transcoding and HLS

0

Transcoding the input stream to the smaller twos:

ffmpeg -re -v info -i "rtmp://localhost/live/stream live=1" \
-c:v libx264 -b:v 500k -vf scale=540:-1 -preset faster -copyts \
-c:a aac -b:a 64k -ac 2 -flags +global_header \
-f flv "rtmp://localhost/live/500k live=1" \
-c:v libx264 -b:v 800k -vf scale=720:-1 -preset faster -copyts \
-c:a aac -b:a 64k -ac 2 -flags +global_header \
-f flv "rtmp://localhost/live/800k live=1"

Then I need relay them to AMS livepkgr HLS app:

ffmpeg -re -v info \
-i "rtmp://localhost/live/500k live=1" \
-c copy -copyts -flags +global_header \
-f flv "rtmp://localhost/livepkgr/500k?adbe-live-event=liveevent" \
-i "rtmp://localhost/live/800k live=1" \
-c copy -copyts -flags +global_header \
-f flv "rtmp://localhost/livepkgr/800k?adbe-live-event=liveevent"

The resulting streams are not keyframe aligned. Any chance to make then so with ffmpeg like FMLE encoder does? Thanks for an attention.

vayvanne

Posted 2016-02-13T03:34:25.163

Reputation: 71

Add -g value to each encode. – Gyan – 2016-02-13T06:08:08.433

Thank you. -g seems deprecated. I have found -x264opts keyint=8:min-keyint=8:no-scenecut but the problem is not actually with putting the keyframe but getting it aligned in both streams. The ffmpeg transcoding above does not start the both streams at the same time, there is a slight shift. In case of FMLE the livepkgr app produces up to 3 streams aligned but ffmpeg does not. Should be a trick to tell the livepkgr app produce properly aligned streams files as it does in case when encoder is FMLE. – vayvanne – 2016-02-14T00:41:20.590

Answers

0

Try

ffmpeg -re -v info -i "rtmp://localhost/live/stream live=1" \
-filter_complex "[0:v]split[a][b];[a]scale=540:-1[oa];[b]scale=720:-1[ob]" \
-map [oa] -c:v libx264 -b:v 500k -preset faster -copyts \
-map 0:a -c:a aac -b:a 64k -ac 2 -flags +global_header \
-f flv "rtmp://localhost/live/500k live=1" \
-map [ob] -c:v libx264 -b:v 800k -preset faster -copyts \
-map 0:a -c:a aac -b:a 64k -ac 2 -flags +global_header \
-f flv "rtmp://localhost/live/800k live=1"

Gyan

Posted 2016-02-13T03:34:25.163

Reputation: 21 016

Wow. Thanks for the great idea with filter @Mulvya. Seems that shift is introducing by relay script above which starts the output streams not at the same time really. I implemented the same idea of splitting/mapping for livepkgr too and it works perfectly. Test player is here link to check. But this doubles CPU usage on transcoding. Any chance avoid the double transcoding job and start output streams at the same time for the relay scenario above? For the case if output is of three streams?

– vayvanne – 2016-02-27T03:31:03.113