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 <[email protected]> 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
> [email protected]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
> 
> To unsubscribe, visit link above, or email
> [email protected] with subject "unsubscribe".

_______________________________________________
ffmpeg-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".

Reply via email to