Is there a way to tell ffmpeg "encode file A with format settings of file B?"

0

I know I could use ffprobe and then parse the text file to get the codec info of file B, but is there a simpler way?
Goal: I want to append a few seconds of silence to hundreds of audio files (who have different bitrates and encodings) without reencoding, because I would like to have a few seconds of silence between tracks when playing a playlist. Since there is no audio player on Android that offers this functionality (to my knowledge), I'm considering incorporating the silence within the files themselves.

Mia Lon

Posted 2018-12-23T16:37:59.880

Reputation: 1

3

Your question unfortunately exhibits the XY problem. Your actual problem is finding an Android player that offers gaps between tracks, or how to play music on Android with gaps in between. Doing what you think is the solution with ffmpeg is not really possible. I would recommend to ask on [Android.SE] about the Android issue.

– slhck – 2018-12-23T17:24:32.170

1It definitely IS possible to use ffprobe to read out the codec and bitrate of an audio file,
pipe it into a text file, parse it and then encode my 11-sec audio file of silence with the same codec and bitrate. Then just join them.
– Mia Lon – 2018-12-23T20:34:48.577

I was merely wondering if there was an easier way. I'm pretty sure that there is no Android player with that functionality, and even if there was, it would only work there. Chances are I would not want to use it for lack of other functions. The only nice player so far is the integrated player of TotalCommander. All other fail in very basic functionality like ignoring MP3 tags, quickly creating playlists or editing them. It's either very cumbersome or flat out impossible. – Mia Lon – 2018-12-23T20:51:32.397

If you encoded silence with the same format, how exactly did you combine that with the original track? But yes, that's the only possible way to achieve that, as ffmpeg does not have a functionality like the one you've asked for. – slhck – 2018-12-23T22:55:43.780

Sure it does: (https://trac.ffmpeg.org/wiki/Concatenate)

– Mia Lon – 2018-12-29T20:14:36.567

Answers

0

To answer your literal question, no, ffmpeg cannot determine the input codec and bitrate and apply the same settings to the output file.

There are several reasons why it wouldn't be easy to implement:

  • You'd have to determine the output encoder based on the input codec. You can't always know which encoder was used for the original file, so selecting the exact same encoder will not be possible in all cases.
  • Choosing the same input bitrate might lead to generation loss, so the user should select an appropriate bitrate or quality level for the output themselves.
  • Keeping sample rate and number of audio channels (or pixel formats, frame rate for video) is usually supported, but there are edge cases where, for example, an input may have a 5.1 audio stream, but the only audio encoder that ffmpeg can choose only supports stereo audio encoding.
  • There are lots of combinations of input/output codecs with file formats, where you can't guarantee that a given input combination can be written to an output file.

That said, for a limited use case such as yours, a simple script that parses file information (e.g., with mediainfo or ffprobe) and translates that into ffmpeg settings would work.

slhck

Posted 2018-12-23T16:37:59.880

Reputation: 182 472