2

I am using the script below to transform videos to MPEG-DASH compliant ones. I want also to be able to process video that have no audio and/or no subtitles. Because of that I marked the streams for audio and subtitles with a ? at the end of the stream specifier, f.e. -map a:0?.

Now when I want to specify the adaptation sets I can set it for the video and audio streams with id=0,streams=v and id=1,streams=a, but I can not select the subtitle streams, like I would want to with id=2,streams=s, as it is stated in the docs ("To map all video (or audio) streams to an AdaptationSet, "v" (or "a") can be used as stream identifier instead of IDs."). The only thing I could do is to specify an ID, like id=2,streams=8, but for that to work, an audio and subtitle stream would be mandatory, because otherwise there is no stream with the id 8 and FFmpeg would fail. I thought of putting the -map s:0? at the first position, then I could be sure, that it is always the stream with id 0, but if the input did not have a subtitle stream, then there would be an additional adaptation set, with the first version of video. I also thought about using FFprobe to get info about the available streams, but did not look too much into depth.

Does anybody know how I could tell FFmpeg, that an adaptation set should be created, when there's a stream with subtitles present independent of there being audio streams or not?

Any help is much appreciated.

#!/bin/bash

INPUT_PATH=$1
OUTPUT_PATH=$2

FPS=25
GOP_SIZE=100
PRESET_P=veryfast
V_SIZE_1=256x144
V_SIZE_2=426x240
V_SIZE_3=640x360
V_SIZE_4=854x480
V_SIZE_5=1280x720
V_SIZE_6=1920x1080

ffmpeg -i "$INPUT_PATH" \
    -preset $PRESET_P -keyint_min $GOP_SIZE -g $GOP_SIZE -sc_threshold 0 \
    -r $FPS -c:v libx264 -pix_fmt yuv420p -c:a aac -c:s copy \
    -map v:0 -s:0 $V_SIZE_1 -b:v:0 160k -maxrate:0 160k -bufsize:0 320k \
    -map v:0 -s:1 $V_SIZE_2 -b:v:1 450k -maxrate:1 450k -bufsize:1 900k \
    -map v:0 -s:2 $V_SIZE_3 -b:v:2 1M -maxrate:2 1M -bufsize:2 2M \
    -map v:0 -s:3 $V_SIZE_4 -b:v:3 2.5M -maxrate:3 2.5M -bufsize:3 5M \
    -map v:0 -s:4 $V_SIZE_5 -b:v:4 5M -maxrate:4 5M -bufsize:4 10M \
    -map v:0 -s:5 $V_SIZE_6 -b:v:5 8M -maxrate:5 8M -bufsize:5 16M \
    -map a:0? -b:a:0 128k -ac:a:0 1 \
    -map a:0? -b:a:1 384k -ac:a:1 2 \
    -map s:0? \
    -use_template 1 -use_timeline 1  \
    -seg_duration 4 -adaptation_sets "id=0,streams=v id=1,streams=a id=2,streams=s" \
    -f dash "$OUTPUT_PATH"
Sebsii
  • 41
  • 2
  • I asm not sure why you are getting downvoted - it may be because the domain is complex and your question is quite involved. It might be worth trying to simplify the question - I think the key thing you want to know is: " how I could tell FFmpeg, that an adaptation set should be created, when there's a stream with subtitles present independent of there being audio streams or not?"./ You may also find it easier to get an answer on the SuperUser stack exchange - e.g.https://superuser.com/q/753703 – Mick Jun 30 '21 at 09:10
  • 1
    Yeah, I am not sure either why I am getting downvoted. Please let me know how I should change my question in order to be answerable. @Mick Thank you for your suggestions – Sebsii Jun 30 '21 at 12:19
  • 1
    To make inconsistent input have a consistent output, I think you are going to need to customize your ffmpeg command for each run, which would mean parsing ffprobe or the manifest xml itself. – Grady Player Jul 15 '21 at 13:49

0 Answers0