jarno
jarno

Reputation: 856

How to retain format in conversion by 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?

Upvotes: 4

Views: 2945

Answers (1)

Harald Nordgren
Harald Nordgren

Reputation: 12399

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"

Upvotes: 3

Related Questions