2

Is it possible to remove only image based subtitles using ffmpeg? I know that you can manually select/exclude streams using -map, however I'm trying to automate this process, and the input files have a mix of image based subtitles (pgssubs) and text based subtitles. Since I'm trying to encode to an MP4 container, the image based subtitles are incompatible.

1 Answer 1

1

Sorry, I cannot write the script but here is the idea. First get the codec_name of your text-based subtitle from a video

ffprobe -v error -show_entries stream=codec_name -of default=noprint_wrappers=1 <test video name>

Now replace with that with that codec name in te following script.

Usage: imgsrtremover <file name>
Output: <filename without extention>.mp4
#! /bin/bash
imgsrtstreams=$(ffprobe -v error -show_entries stream=codec_name -of default=noprint_wrappers=1 $1 | grep -n "<codec>" | cut -f1 -d:)
cmd="ffmpeg -i $1 -map 0"
for i in $imgsrtstreams
do
cmd+=" -map -0:$((i-1))"
done 
$cmd -c copy $(echo "$1" | rev|cut -f 2- -d '.'|rev).mp4  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.