Opened 3 years ago

Last modified 3 years ago

#9066 new enhancement

Enable explicit output extension

Reported by: tes45t Owned by:
Priority: wish Component: ffmpeg
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

I am making an application that uses FFmpeg to edit media files. The user selects input file, then selects output file and then selects extension. For example, user can do this:

Input: C:/path/to/video.mp4
Output: C:/path/to/edited.some-custom-extension
Extension: "gif"

Then my program invokes FFmpeg and passes arguments like this:

ffmpeg -i "C:/path/to/video.mp4" <some_other_arguments_here> "C:/path/to/edited.some-custom-extension.gif"

Notice the extra "gif" at the end. After FFmpeg exits, my program renames "edited.some-custom-extension.gif" to "edited.some-custom-extension".

Basically, I want to be able to pass extension to ffmpeg as a separate argument, so that I do not need to rename the file after encoding. I am aware that there are already options for that (such as the -f option), but the string that needs to be passed to -f does not always match the file extension. For example, to encode as "flv", you need to pass "-f flv", but to encode as "mkv", you need to pass "-f matroska". I asked on stack exchange and they said that there is really missing the feature I am looking for.

I would like either a mapping between file extensions and "-f" parameters (I am talking about output files, not input files; for input files FFmpeg can detect the format by file content and file extension is used just as fallback), or a new option that can override the extension (such that it would achieve the EXACT SAME effect as if the output file had that extension). For example, something like this:

ffmpeg -i "C:/path/to/video.mp4" --explicit_extension "gif" "C:/path/to/edited.some-custom-extension"

Change History (7)

comment:1 by Marton Balint, 3 years ago

IMHO this is a too specific feature to implement in ffmpeg. The proper way is to specify the muxer with -f. You should use the av_guess_format API call directly to acquire the muxer name to be used.

comment:2 by tes45t, 3 years ago

Sorry, but I think this is the most fundamental feature. Deducing muxer info from the output file extension, while lacking explicit extension-muxer mapping, seems unnecessarily restrictive. There are a lot of use cases I experienced when I want extensionless output and want to do it programmatically. Also av_guess_format is an API function. I can ask my users to download FFmpeg binaries, but I can't force them to compile my program from source in order to include libavformat APIs (and also that would imply version dependency incompatibilities if user's FFmpeg is different version).

comment:3 by Elon Musk, 3 years ago

This is pointless, one can already provide extension and muxer will be auto-guessed.

comment:4 by tes45t, 3 years ago

@richardpl Have you read the issue entirely? The point is that I deliberately want to have different extension in the output file name. For example, I want to encode as ".mkv" but I want output file to be "file.png". The problem is that there is currently no standard way to programmatically retrieve the mapping between output file extensions and muxer names (and muxer options). FFmpeg automatically guesses the muxer and muxer options when you specify output file extension, but as said, I have a lot of use cases when I want to have different extension, or no extension at all, but I want FFmpeg to behave like the output file have the extension I want. That's why I propose such option. Please let me know if anything in the issue is unclear.

comment:5 by Gyan, 3 years ago

I had a (now dormant) patch for this. It got bike-shedded over const-correctness and then the pandemic happened. I'll revive it in the next few weeks.

Last edited 3 years ago by Gyan (previous) (diff)

comment:6 by Carl Eugen Hoyos, 3 years ago

Keywords: ffmpeg output file extension type format removed
Priority: normalwish

The suggestion does not sound like a good idea to me and the fact that gif was used as an example doesn’t help either.

comment:7 by tes45t, 3 years ago

@cehoyos That sounds like a too personal opinion. File extension is just a part of the file name. Forcing a part of the file name to be the only way to influence the muxer seems like a bizarre constraint to me. That would be like if your nickname "cehoyos" means that you must work on operating systems, because it ends with "os". But, as we know, you don't work on developing an operating system, but instead you work on ffmpeg. Then, why is your nickname not "cehoyffmpeg"? Isn't that misleading? Or if my personal name is Patrick and I work in a bakery, should I change my personal name to Patribakery?

I asure you that a lot of developers from my team share my opinion. If you want, I can ask all of them to register on this website and upvote this feature request or post a comment. File extension is just a string, and should be totally unrelated to the ffmpeg encoding parameters. It is just a file name, it should not dictate or influence any encoding algorithms or muxer options. Besides that, I don't see the reason for your expressing your personal opinion regarding this, since @Gyan said that they already have a patch for this. I would suggest waiting a few weeks until @Gyan's patch is merged and refrain from further discussing about this topic until then. Thanks.

Note: See TracTickets for help on using tickets.