How to combine a .MP4 video with a .WAV audio to create a new .MP4 video using ffmpeg from command line arguments? - audio

I want to merge a .WAV audio file with a .MP4 video file to create a new .MP4 video file.
And i am currently using the following codes to do that :
ffmpeg -i input_vid.mp4 -i input_audio.wav -vcodec copy -acodec copy output.mp4
But it is only creating output.mp4 file but no videos embedded with that means if i am playing that output.mp4 file then nothing is playing.
And i don't know where i am doing wrong so that it is creating like this.
I know this type of questions already asked by may persons but that didn't help me much so if anybody can find where i am doing wrong or how to solve this problem please help me to solve my problem.

Remove -acodec copy. That option forces a direct copy of the WAV bytes into MP4's audio track.
A valid audio MP4 must contain an MPEG audio track (mp3 or aac). Once you remove -acodec copy then FFmpeg will still copy the video (picture) part but also automatically encode from WAV to AAC for you. AAC is the standar audio codec inside MP4 files (can add MP3 too since all 3 formats are compatible MPEG files).

Related

Incorrect values for song length (duration) in Mp3tag after ffmpeg FLAC to MP3 conversion

The problem
As per this post, I use the following command to convert a flac file to mp3 while keeping all metadata:
ffmpeg -i input.flac -ab 320k -map_metadata 0 -id3v2_version 3 output.mp3
When inspecting the converted mp3 file by right-clicking it, going to properties and then details, everything looks in order. The value for "Length" is correct.
When inspecting the converted mp3 file with Mp3tag, the value for "Length" is different. From my testing, the "Length" value is consistently about 28% of what it is supposed to be.
Normally, this isn't an issue. Most music players I use, read the correct length value, same as Windows. However, I've recently discovered that Spotify Mobile for some reason ignores the length value that can be seen in the Windows panel and uses the one that can be seen in Mp3tag.
I want to figure out what command I should use so that after the flac file has been converted to mp3, Mp3tag shows the correct length, and there by, Spotify Mobile reads the correct length as well.
What I have tried
1.
After converting the file to Mp3, I've tried reencoding the mp3 file into a... mp3 file using the following command:
ffmpeg -i original.mp3 -c:v copy -c:a mp3 -vn -ar 44100 -ac 2 -b:a 320k copy.mp3
As can be seen in the image above, this fixes the issue and the length is showing correctly in Mp3tag and in Spotify Mobile.
Issues with this: Reencoding reduces quality and I don't know how to combine the previous flac conversion command and this one into one line.
2.
I tried https://cloudconvert.com/flac-to-mp3 and it worked. The length is displayed correctly in Mp3tag. (What commands did they use on the server???)
Issues with this: I don't want to rely on a cloud service for conversion, I have a lot of files to convert and I'd prefer it to be done locally.
Some demo files
Here is a folder with a flac file, a bad mp3 file (wrong length) and a good mp3 file. It looks like if you preview the music in google drive, it also plays the wrong length for the bad mp3 (39s not 2m19s), while vlc, groove player, spotify (desktop not mobile) all play the correct full length (2m19s) for the bad mp3 file.
Folder: here's the link
It seems I had an outdated version of ffmpeg... (ffmpeg version git-2020-05-23-26b4509) I updated to the latest version and the issue went away. Learned my lesson the hard way.
Would still appreciate an explanation on why this was happening. I'm curious. Why were there two values for length?

When using youtube-dl with ffmpeg, what merge extension(mkv/mp4) can get best sound quality

I use youtube-dl -F to display all video/audio list, and choose best video/audio source myself.
Then I use youtube-dl -f [video code]+[audio code] to download and automatically merge them.
As question title, when I use --merge-output-format, what output extension should be chosen then I can get a file with best sound quality. Is mkv? Or is most suitable merge extension related to the extension of video/audio source?
By the way, my using player is PotPlayer.
It doesn't really matter
MKV or MP4 can accept all of the video and audio formats currently available on YouTube (H.264 or VP9 or AV1 video, AAC or Opus audio). Exception is if you are using a really old ffmpeg.
youtube-dl is just re-muxing the video and audio with --merge-output-format. Like a copy and paste. There is no re-encoding so there is no generation loss.
If you choose an incompatible output format, then it will fail with ERROR: Stream #1:0 -> #0:1 (copy) or similar.
Use whichever you prefer or works best for your player/device.

FFMPEG - Merge Video-A with audio of of Video-B in a single command? [duplicate]

This question already has answers here:
How to add a new audio (not mixing) into a video using ffmpeg?
(10 answers)
Closed 3 years ago.
I would like to use the video of video A, and put the audio of video B on top. How would I do this with ffmpeg in the command line? I have found tutorials to do this with extracting the audio first to a wav file, but I was wondering whether it's possible to do this in a single command? and without transcoding everything again?
edit: both files are .mp4 files and both contain video & audio. both files are of equal length.
Basic command form is
ffmpeg -i videoA -i videoB -map 0:v -map 1:a -c copy videoAaudioB.mp4
Basic requirement is that A's video and B's audio should be compatible with file format of the output.

exporting ogg videos from video slideshow (mp4) and audio (wav) using ffmpeg in python

I have tried to find a solution already, but just cannot make it work. I want to export an .ogg-video by combining a video slideshow (mp4) with an audio file (wav) by using ffmpeg in python. The audio is shorter than the video and should have an offset of 2000 milliseconds, so that it starts approximately in the middle of the video. The code that I tried is essentially this:
subprocess.call('ffmpeg.exe -itsoffset 0 -i slideshows/slideshow.mp4 -itsoffset 2000 -i sounds/audio.wav -codec:v libtheora -codec:a libvorbis output.ogg', shell= True)
FYI: I need to create a couple of different video formats from the video and audio input, so substituting the ogg with a different format is no option. I have already successfully created .mp4-video-files and .webm-video-files from the material, but need the .ogg in addition. Also, Power Point does not like any of the exported videos, maybe this might be relevant for finding the problem here (I also unsuccessfully tried to fix this issue).

Extract audio from video with FFMPEG but not the same duration

My problem is that i need to extract with FFMPEG the audio contained in a video with the same duration. But for some files that i tested, the audio's duration is sometimes shorter than the video's duration. I need to have the exact same duration between the audio and the video file.
The command that i have already tried is this following:
ffmpeg -i input_video.mp4 output_audio.wav
How can i fix this with options in my command ?
I found the solution. To get an audio extract with the exact same length. I use the option -async 1 like this:
ffmpeg -i input_video.mp4 -async 1 output_audio.wav

Resources