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.

5
  • 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 Enthusiasts about the Android issue.
    – slhck
    Dec 23, 2018 at 17:24
  • 1
    It 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
    Dec 23, 2018 at 20:34
  • 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
    Dec 23, 2018 at 20:51
  • 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
    Dec 23, 2018 at 22:55
  • Sure it does: (trac.ffmpeg.org/wiki/Concatenate)
    – Mia Lon
    Dec 29, 2018 at 20:14

1 Answer 1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .