videoffmpegmpeg-dashtranscoding

FFMPEG Picture in picture with DASH


I'm using FFMPEG to transcode a video into different resolutions and it's working fine. But now I want to merge two videos picture in picture, as one video, which then has to be transcoded into different resolutions.

The command below is what I've got so far. Unfortunately, it works only for the 170p resolution. If I switch the player to 720p the overlay video is gone.

I guess I have to use some kind of naming scheme for the merging files and the different resolutions, so FFMPEG can differentiate between them. But how am I going to do that?

FFMPEG Command

ffmpeg \
-re \
-i "input.webm" \
-i "overlay.webm" \
-filter_complex "[1]scale=iw/3:-1[pip];[0][pip]overlay=W-w-10:10:shortest=1[v];[0:a][1:a]amerge[a]" \
-r 30 \
-usage lowlatency \
-qp_b 1 \
-quality ultrafast \
-level 2.0 \
-map "[v]" \
-map "[a]" \
-map 0 \
-c:a aac \ 
-c:v h264_qsv \
-b:v:1 1800k \
-s:v:1 1280x720 \
-b:v:0 300k \
-s:v:0 320x170 \
-profile:v:0 main \
-profile:v:1 main \
-bf 1 \
-keyint_min 30 \
-g 30 \
-sc_threshold 1 \
-b_strategy 0 \
-ar:a:1 96000 \
-seg_duration 1 \
-remove_at_exit 0 \
-streaming 1 \
-window_size 10 \
-adaptation_sets "id=0,streams=v id=1,streams=a" \
-utc_timing_url https://time.akamai.com/?iso \
-live 1 \
-f dash "manifest.mpd" 

Solution

  • I figured it out.

    I thought about what I said about the naming schema and couldn't find any documentation for anything like that. So I simply added another -filter_complex and changed the [v] to [v2] like that: -filter_complex "[1]scale=iw/3:-1[pip];[0][pip]overlay=W-w-10:10:shortest=1[v2];[0:a][1:a]amerge[a]". And I changed the second resolution from main to baseline, but I didn't test if this has any effect.

    Then I just maped it to the second video resolution:

    -map "[v2]" -map "[a]"

    So you end up with this command:

    Working command

    ffmpeg \
    -re \
    -i "input.webm" \
    -i "overlay.webm" \
    -filter_complex "[1]scale=iw/3:-1[pip];[0][pip]overlay=W-w-10:10:shortest=1[v];[0:a][1:a]amerge[a]" \
    -filter_complex "[1]scale=iw/3:-1[pip];[0][pip]overlay=W-w-10:10:shortest=1[v2];[0:a][1:a]amerge[a]" \  <-- Added
    -r 30 \
    -usage lowlatency \
    -qp_b 1 \
    -quality ultrafast \
    -level 2.0 \
    -map "[v]" \
    -map "[a]" \
    -map "[v2]" \   <-- Added
    -map "[a]" \    <-- Added
    -c:a aac \ 
    -c:v h264_qsv \
    -b:v:1 1800k \
    -s:v:1 1280x720 \
    -b:v:0 300k \
    -s:v:0 320x170 \
    -profile:v:0 main \
    -profile:v:1 baseline \  <-- Changed from main
    -bf 1 \
    -keyint_min 30 \
    -g 30 \
    -sc_threshold 1 \
    -b_strategy 0 \
    -ar:a:1 96000 \
    -seg_duration 1 \
    -remove_at_exit 0 \
    -streaming 1 \
    -window_size 10 \
    -adaptation_sets "id=0,streams=v id=1,streams=a" \
    -utc_timing_url https://time.akamai.com/?iso \
    -live 1 \
    -f dash "manifest.mpd"