Advertisement
Guest User

copy_metadata

a guest
May 26th, 2018
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.01 KB | None | 0 0
  1. function copy_metadata
  2. {
  3.     if [ $# -eq 2 ]
  4.     then
  5.         has_video=$(ffprobe -v error -select_streams v:0 -show_entries stream=codec_name -of default=noprint_wrappers=1 -pretty "$1")
  6.         has_audio=$(ffprobe -v error -select_streams a -show_entries stream=codec_name -of default=noprint_wrappers=1 -pretty "$1")
  7.         if [[ $has_video = *"codec_name"* ]] && [[ $has_audio = *"codec_name"* ]]
  8.         then
  9.             setting="-map_metadata:s:v 0:s:v -map_metadata:s:a 0:s:a"
  10.         elif [[ $has_video = *"codec_name"* ]] && [[ -z "$has_audio" ]]
  11.         then
  12.             setting="-map_metadata:s:v 0:s:v"
  13.         elif [[ -z "$has_video" ]] && [[ $has_audio = *"codec_name"* ]]
  14.         then
  15.             setting="-map_metadata:s:a 0:s:a"
  16.         fi
  17.         outname="${2%.*}"
  18.         outname_ext="${2##*.}"
  19.         ffmpeg -i "$1" -i "$2" -map 1 -c copy -map_metadata 0 ${setting} "${outname}"_new.$outname_ext
  20.     else
  21.         echo "\nTwo input files needed, first the one with the metadata that will be copied from and second the one without metadata that media streams will be copied from\n"
  22.     fi
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement