Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retain format in conversion by FFmpeg?

Tags:

file

ffmpeg

Suppose the input file does not have filename extension. FFmpeg detects input file format, but how to use the same format for output file automatically?

like image 990
jarno Avatar asked Oct 20 '25 17:10

jarno


1 Answers

Try this script. For an input file without an extension we use ffprobe to figure out a suitable extension, and tack it on to the output file.

Run it like ./script.sh input_file_wtithout_extension

#!/usr/bin/env bash

input_file="$1"
extension=$(ffprobe "$input_file" -show_entries format=format_name -v quiet |\
    grep -oP 'format_name=\K\w+')

output_file="$input_file".$extension
ffmpeg -y -i "$input_file" -strict -2 $options "$output_file"
like image 171
Harald Nordgren Avatar answered Oct 23 '25 12:10

Harald Nordgren



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!