0

I have an LG CX TV. The internal video player does not recognise DTS audio format. I'd like to be able to play MKV files (which might have DTS audio tracks) from an external USB device. I was looking into an ffmpeg command that will:

  • Leave any and all existing video tracks untouched
  • Leave any and all existing subtitles tracks untouched
  • Leave any and all existing audio tracks untouched, but crucially - also convert them all to AC3 audio format (at its best quality) and mux them back into the mkv

What ffmpeg command would I need here? So far I think I have it mostly right with this one, but I think this just converts the audio tracks to AC3, not retains the original ones and create AC3 copies.

ffmpeg -i input.mkv -map 0 -vcodec copy -scodec copy -acodec ac3 -b:a 640k output.mkv
1
  • Your command looks correct. You may use MediaInfo or FFprobe for checking the streams and the codecs of the input and the output MKV files.
    – Rotem
    Commented Mar 9 at 21:11

1 Answer 1

0

bash script:

#!/bin/bash
f="input.mkv"
COD=($(ffprobe -v 0 -select_streams a -show_entries stream=codec_name -of default=nw=1:nk=1 "$f"))
echo ${!COD[@]} → ${COD[@]} → ${#COD[@]}
MAP=()
ENC=()
AU1=${#COD[@]}
for i in "${!COD[@]}"; do
  if [ "${COD[$i]}" != "ac3" ]; then
    MAP+=("-map" "0:a:${i}")
    ENC+=("-c:a:$AU1" "ac3")
    ((AU1++))
  fi
done
ffmpeg -i "$f" -map 0 "${MAP[@]}" -c copy "${ENC[@]}" /tmp/output.mkv -y
ffplay /tmp/output.mkv

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .