Preserving Video Integrity While Increasing Volume - Is It Possible?

Started by jdoejdoe, August 30, 2024, 11:29:36 AM

Previous topic - Next topic

jdoejdoe

I'm looking for a way to create a new video that has increased volume compared to the original video, without changing any other aspects of the video, including the EXIF data. My goal is to make the audio more audible without giving the impression that the video has been tampered with.

Is it possible to achieve this? If so, how?

StarGeek

It's not possible with exiftool, as it does not edit the actual stream data or any metadata in the streams.

I faintly remember reading about using ffmpeg to be able to edit a stream setting to do this. Asking ChatGPT (which is usually pretty accurate with ffmpeg commands), it responded with this
QuoteFor instance, with MP4 files, you can use the -metadata:s:a option to set the volume attribute for the audio stream, though this is not widely supported and might not work on all players.

However, you need to understand that if there is actual EXIF data (most video data is Quicktime data), you cannot make any edits to the file without losing the EXIF data. EXIF data is non-standard in a video file, and every company forces it into the file in different ways. Because of this, it cannot be copied to a new file. The same goes for time GPS data, such as a GPS track.

You can use this command to see if there is any actual EXIF data in the file
exiftool -G -a -s file.mp4

You can use this command to see if there's a GPS track in the file. If it's a big file, there will be a lot of data listed, so you probably should hit Ctrl+C once you see it
exiftool -ee3 "-GPS*" file.mp4
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

wywh

Use ffmpeg to extract audio, increase its volume with the desired app, remux audio back to original video with ffmpeg, copy metadata from the original movie with exiftool. Disclaimer: It should work but I have not tried it.

StarGeek

There would be no need for the external app, ffmpeg can adjust audio levels on its own. See Audio Volume Manipulation.

Quicktime data can be copied, but as I said, any actual EXIF data and GPS tracks will be lost.

I've never tested ffmpeg metadata copying abilities, so I don't know how it might deal with something like Description which can appear in six different places. I suspect that it would copy it to the one location regardless of which group it originally was in.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

jdoejdoe

Quote from: StarGeek on August 30, 2024, 12:21:51 PMThere would be no need for the external app, ffmpeg can adjust audio levels on its own. See Audio Volume Manipulation.

Quicktime data can be copied, but as I said, any actual EXIF data and GPS tracks will be lost.

I've never tested ffmpeg metadata copying abilities, so I don't know how it might deal with something like Description which can appear in six different places. I suspect that it would copy it to the one location regardless of which group it originally was in.


Sorry I didn't make my post clear. My thought was ffmpeg or a similar tool to just boost audio loudness.

I know some posts say ffmpeg doesn't reencode so the original tags will not be affected. But any time the video will be remuxed I forsee exifdata gps data lost.

My question is if I have the original files can all of the exifdata including all dates and tags be cloned onto the new loud file or will it not be possible as I'm not sure what the exiftool cannot overwrite or clone.

Thanks for taking the time, this noob is thankful and will appreciate a little more guidance

wywh

Quote from: StarGeek on August 30, 2024, 12:21:51 PMffmpeg metadata copying abilities, so I don't know how it might deal with something like Description which can appear in six different places. I suspect that it would copy it to the one location regardless of which group it originally was in.

Apple's apps use Keys metadata in movies and this simple lossless ffmpeg command should preserve them:

ffmpeg -i input.mp4 -c copy -movflags use_metadata_tags -map_metadata 0 output.mp4
...unfortunately even ffmpeg7 still has a 10 year old issue which incorrectly writes metadata (GUI applications usually use ffmpeg under the hood so they misbehave the same) so you must then fix it with exiftool so Photos.app and QuickTime Player can read it:

exiftool -m -overwrite_original -api LargeFileSupport=1 -Keys:All= -tagsFromFile @ -Keys:All output.mp4
That said, I don't even try to use ffmpeg and use just:

ffmpeg -i input.mp4 -c copy output.mp4
...and copy metadata from the originals:

exiftool -m -overwrite_original -api QuickTimeUTC=1 -api LargeFileSupport=1 -tagsFromFile input.mp4 -All:All '-FileCreateDate<QuickTime:CreateDate' '-FileModifyDate<QuickTime:CreateDate' output.mp4
- Matti

StarGeek

Quote from: jdoejdoe on August 30, 2024, 12:29:48 PMI know some posts say ffmpeg doesn't reencode so the original tags will not be affected. But any time the video will be remuxed I forsee exifdata gps data lost.

ffmpeg can copy direct streams with something like -c copy, but it always writes a new file, and it is the act of creating the new file where EXIF/GPS tracks are lost.

QuoteMy question is if I have the original files can all of the exifdata including all dates and tags be cloned onto the new loud file or will it not be possible as I'm not sure what the exiftool cannot overwrite or clone.

As I said, actual EXIF/GPS track data is lost, because it is non-standard and there isn't a legitimate place in the file to put it. Exiftool can copy most header level Quicktime tags and any XMP tags (which are uncommon in videos) from the original to the new file. But because Quicktime data is open, new (often unnecessary) tags are being added all the time. Exiftool won't be able to copy those until a definition is created.

Exiftool can't copy any stream level metadata in a video, but I think ffmpeg usually will if the -map_metadata 0 is included. No guarantee though.

QuoteThanks for taking the time, this noob is thankful and will appreciate a little more guidance

Everybody was a noob at some point. And when you are new to something, you may not know the technically terms need to "read the f* manual" that so many more experienced people might know. People who simply reply RTFM are one of my pet peeves (to put it kindly).
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

StarGeek

Quote from: wywh on August 30, 2024, 12:56:34 PMThat said, I don't even try to use ffmpeg and use just:

ffmpeg -i input.mp4 -c copy output.mp4

Here's a better command, -hide_banner is optional, but removes all the stuff at the beginning of the output
ffmpeg -hide_banner -i input.mp4 -c copy -map 0 output.mp4

-c copy -map 0 means that it will copy all streams. using only -c copy, then only the first stream of each type will be copied. Usually unnecessary for home videos and such, but for files with multiple audio/subtitle tracks, it will copy all of them.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

jdoejdoe

Quote from: StarGeek on August 30, 2024, 04:49:54 PM
Quote from: wywh on August 30, 2024, 12:56:34 PMThat said, I don't even try to use ffmpeg and use just:

ffmpeg -i input.mp4 -c copy output.mp4

Here's a better command, -hide_banner is optional, but removes all the stuff at the beginning of the output
ffmpeg -hide_banner -i input.mp4 -c copy -map 0 output.mp4

-c copy -map 0 means that it will copy all streams. using only -c copy, then only the first stream of each type will be copied. Usually unnecessary for home videos and such, but for files with multiple audio/subtitle tracks, it will copy all of them.


Thanks.

I'm assuming in all these commands, for e.g. -i input.mp4 I input the file path where the input.mp4 is located. And do I also have to give it the output file path.

Terminal allows drag and dropping files for file paths so that could come handy to not type the entire file path and name. Since I've never done terminal this will help with clarity.

I'm on a Mac and will try terminal, if that doesn't work will give the gui tool a go.

And is there like a master command that clones every possible detail in the video. I used the gui tool and it outputed a .txt file with everything from the original file that I intend to enhance audio for.

There was no import button in the gui. Wanted to ask if there is a command to either clone or pull all metadata from a txt or csv file for most accuracy.

Thanks for not mentioning rtfm

wywh

QuoteI'm assuming in all these commands, for e.g. -i input.mp4 I input the file path where the input.mp4 is located. And do I also have to give it the output file path.

Terminal allows drag and dropping files for file paths so that could come handy to not type the entire file path and name.

I usually cd to the working directory so I don't have to type or drag'n drop files or folders as paths. Then I can use tab key to fill in rest of the input file name after typing few characters from the start. I use paths only if I have to deal with files that have identical names or if I want to keep input and output files in separate folders.

When testing a prebuilt binary I might first just put it in the working directory and launch it without setting a proper path:

./ffmpeg   
zsh: killed     ./ffmpeg

...ouch: macOS refused to open it before clearing the quarantine flag (can also be done by launching the binary in Finder via ctrl-click > Open):

xattr -l ffmpeg
com.apple.macl:
com.apple.quarantine: 0083;66d2dc12;Safari;523DA076-2410-4509-BAFE-2187D689274F

...this clears the quarantine flag:

xattr -d com.apple.quarantine ffmpeg

xattr -l ffmpeg                     
com.apple.macl:

...then the new version can be tested:

./ffmpeg                           
ffmpeg version 7.0.2-tessus  https://evermeet.cx/ffmpeg/  Copyright (c) [2000-2024 the FFmpeg developers
[snip]

- Matti