[FFmpeg-user] Automatically set codec

DopeLabs dopelabs at dubstep.fm
Sat Jun 24 09:03:16 EEST 2017


Generally this would be done first by analyzing the file before running the ffmpeg command. Usually in the form of a small script. 

Though scripting is not on topic for this mailing list, here is one anyways.

dependencies:

mediainfo
ffmpeg 

------------------------------

#!/bin/bash

cid="$(mediainfo --Inform="Video;%CodecID%" "$1")";

if [ "$cid" = "avc1" ]
  then
        echo "CodecID: $cid - Copy";
        ffmpeg -i "$1" -c:v copy ;
  else
        echo "CodecID: $cid - Encode";
        ffmpeg -i "$1" -c:v libx264 ;
fi

------------------------------

Execute the script using the input filename as the first argument.

$ ./script.sh /path/to/input/video.mp4


If you have any questions please feel free to reply direct =]

Cheers


> On Jun 22, 2017, at 10:57 23PM, tony_rui <stuwii at 0mel.com> wrote:
> 
> I want to automatically set a codec.
> For example, if the codec of a movie is h264, set -c:v copy. Otherwise, set -c:v libx264.
> Please tell me the way to do.
> 
> Thank you for reading this mail.
> 
> tony_rui
> 
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
> 
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".



More information about the ffmpeg-user mailing list