FFmpeg - Some commands that might be useful for you
#1
FFmpeg is the leading multimedia framework, able to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created. (about)

Where to download?
https://www.ffmpeg.org/download.html

For Windows: https://ffmpeg.zeranoe.com/builds/
FFmpeg is a set of libraries and programs for handling multimedia data but we only need is a single executable for our purposes, so just extract the ffmpeg.exe file from the bin folder within the build you've downloaded, and save it somewhere convenient (eg. C:\Users\NEO\Downloads\)

Convert MP4 to MKV or MKV to MP4 Quickly, Easily, Losslessly
Code:
ffmpeg -i INPUT.M4A -codec copy OUTPUT.MKV
ffmpeg -i INPUT.MKV -codec copy OUTPUT.MP4
As discussed here

Convert AUDIO to WAV
Code:
ffmpeg -i INPUT.MP3 OUTPUT.WAV
ffmpeg -i INPUT.M4A OUTPUT.WAV

Convert MP3 + JPG to MKV for YouTube
YouTube does not recognize mp3. then you have to convert it to video first (for example, mkv). prepare a JPG image with 1280x720 resolution or another HD resolutions
Code:
ffmpeg -loop 1 -framerate 1 -i IMAGE.JPG -i MUSIC.MP3 -c:v libx264 -preset veryslow -crf 0 -c:a copy -shortest OUTPUT.MKV

Convert M4A to MP3 128kbps CBR
Code:
ffmpeg -i INPUT.M4A -codec:a libmp3lame -b:a 128k OUTPUT.MP3
Mix both stereo channels to stereo (useful if L and R channel have big difference in peak values/significant volume differences)
Code:
ffmpeg -i INPUT.M4A -codec:a libmp3lame -b:a 128k -af "pan=stereo|c0<c0+c1|c1<c0+c1" OUTPUT.MP3

Extract audio stream without re-encoding
Code:
ffmpeg -i INPUT.AVI -vn -acodec copy OUTPUT.AAC
ffmpeg -i INPUT.MP4 -vn -acodec copy OUTPUT.M4A

Merge audio and video file
1) Copying the audio without re-encoding
Note: input video don't contain audio
Code:
ffmpeg -i VIDEO.MP4 -i AUDIO.M4A -c copy OUTPUT.MP4
ffmpeg -i VIDEO.MP4 -i AUDIO.WAV -c:v copy -c:a aac -strict experimental OUTPUT.MP4
2) Replacing audio stream
If your input video already contains audio, and you want to replace it, you need to tell ffmpeg which audio stream to take:
Code:
ffmpeg -i VIDEO.MP4 -i AUDIO.WAV -c:v copy -c:a aac -strict experimental -map 0:v:0 -map 1:a:0 OUTPUT.MP4

Normalize audio
First, run this command:
Code:
ffmpeg -i VIDEO.AVI -af "volumedetect" -vn -sn -dn -f null /dev/null
ffmpeg -i VIDEO.MP4 -af "volumedetect" -vn -sn -dn -f null /dev/null
ffmpeg -i AUDIO.WAV -af "volumedetect" -vn -sn -dn -f null /dev/null
Note: Change "/dev/null" with "NULL" in Windows. Then it will have report like this:
Code:
...
[Parsed_volumedetect_0 @ 0x7f8ba1c121a0] mean_volume: -16.0 dB
[Parsed_volumedetect_0 @ 0x7f8ba1c121a0] max_volume: -5.0 dB
...
Use value in max_volume to normalize (5.0 is just example, value will be vary with other files). Then, run this command:
Code:
ffmpeg -i VIDEO.AVI -af "volume=5.0dB" -c:v copy -c:a libmp3lame -q:a 2 OUTPUT.AVI
ffmpeg -i VIDEO.MP4 -af "volume=5.0dB" -c:v copy -c:a aac -b:a 192k OUTPUT.MP4
ffmpeg -i AUDIO.WAV -af "volume=5.0dB" OUTPUT.WAV

Convert any-resolution video into 640x360 letterbox
Most cheap video player have USB port wich can recognize flashdisk contain MKV files. but, if you play movies with resolution not exactly 16:9 it will displayed like this in TV:
Show Content
To displayed correctly like this:
Show Content
You must convert it with this command:
Code:
ffmpeg -i INPUT.MP4 -vf "scale=640:360:force_original_aspect_ratio=decrease,pad=640:360:(ow-iw)/2:(oh-ih)/2" OUTPUT.MP4
ffmpeg -i INPUT.MKV -vf "scale=640:360:force_original_aspect_ratio=decrease,pad=640:360:(ow-iw)/2:(oh-ih)/2" OUTPUT.MKV


Welcome for those of you who want to add another commands. Smile
Reply
#2
I've written this post for another thing, don't want to edit it now, with some functions (concat, cut) you don't have:

You have two videos made in obs.

You want to cut some parts of them, and then/or join them with a video in the middle for transition, to show that there was a cut there.


You can make a 5 seconds video, that just shows an image and muted audio, with ffmpeg.


Videos made with obs don't go well with videos made by ffmpeg.

Specially if they are mkv. I didn't try mp4 videos made with ffmpeg.


Even if you get all the specs identical, audio channels both the same, fps the same, codecs the same, containers the same, wtv. It's some problem with the header or idk what some persons at 4ch wsr told me.


I repeat: Videos made by one program, have a problem mixing with made by other program.


Also, if you cut an obs mkv video with ffmpeg, it won't join with the other mkv obs videos.

If you cut an obs mp4 video (using the obs remux mkv to mp4 tool) with ffmpeg, and cut that with ffmpeg it does join with the other obs videos.




You can create mkv videos from an image, with ffmpeg, with a mute audiotrack, with this:

ffmpeg -loop 1 -i image.png -f lavfi -i anullsrc=r=44100:cl=stereo -strict -2 -c:a aac -t 5 -c:v libx264 -t 5 -pix_fmt yuv420p -vf scale=1364:768 -r 30 output.mkv


(you can google those options, i mostly copy and pasted them)

Btw, -c:v means -codec:video, and there's a whole ffmpeg doc page where it says "aac encoder" "libx264 encoder" (for h.264) and wtv.

Other thing, If you put ffmpeg -i input.mkv output.mp4, it recontains, changes the container, of the output, I'm pretty sure. Also if you don't know that part, https://en.wikipedia.org/wiki/Video_file_format



I also can make a solid color screen video (without the muted audiotrack) with this:


"C:\1234\audacity\ffmpeg\ffmpeg-win-2020\bin\ffmpeg.exe" -f lavfi -i color=color=0x000000 -t 5 blackscreen.mkv




You can cut videos with ffmpeg with this:


"C:\1234\audacity\ffmpeg\ffmpeg-win-2020\bin\ffmpeg.exe" -i "input.mp4" -ss 00:00:00 -t 00:37:35 -c copy output.mp4


-ss is the cut everything before that, and -t is go on for x time, then finish the clip. You have to make that work for your case.


You can concat (paste together videos one after another) videos in a folder, with this:

for %%i in (*.mp4) do echo file '%%i'>> mylist.txt

"C:\1234\audacity\ffmpeg\ffmpeg-win-2020\bin\ffmpeg.exe" -f concat -safe 0 -i mylist.txt -c copy output.mp4

pause


change the extensions to your desired inputs and outputs




Ok, so what's the solution to my initial problem?

Remux everything to mp4 with obs, cut it with ffmpeg, cat it with ffmpeg.

The transition screens, I made them filming an image a couple seconds with obs. If you don't get an image viewer that leaves the screen clean, with only the image, like me, I created the ffmpeg video of an image, then opened the image with vlc, fullscreen, that gave me a clean screen of the image, that I recorded with obs. I recorded it the exact ammount of seconds I wanted it, without later cutting with ffmpeg.

I copied and pasted various transition screens, because I had more than one obs video to concat.

Then I ordered the videos changing their names alphabetically (1.mp4 2.mp4 3.mp4, like that)

All in the same folder, and it worked.




Hopefully you can work with that.





I have the idea but haven't tested it, of maybe passing all the videos through ffmpeg, just -i input.mkv output.mkv; And then all the videos would be "ffmpeg videos", and then they would join. Idk.
Reply
#3
(Mar 29, 2020, 10:20 am)theSEMAR Wrote: Convert any-resolution video into 640x360 letterbox
Most cheap video player have USB port wich can recognize flashdisk contain MKV files. but, if you play movies with resolution not exactly 16:9 it will displayed like this in TV:
Show Content
To displayed correctly like this:
Show Content
You must convert it with this command:
Code:
ffmpeg -i INPUT.MP4 -vf "scale=640:360:force_original_aspect_ratio=decrease,pad=640:360:(ow-iw)/2:(oh-ih)/2" OUTPUT.MP4
ffmpeg -i INPUT.MKV -vf "scale=640:360:force_original_aspect_ratio=decrease,pad=640:360:(ow-iw)/2:(oh-ih)/2" OUTPUT.MKV

I improved the command so that it speeds up the conversion process.
Code:
ffmpeg -i INPUT.MP4 -vf "scale=640:360:force_original_aspect_ratio=decrease,pad=640:360:(ow-iw)/2:(oh-ih)/2" -acodec copy OUTPUT.MP4
ffmpeg -i INPUT.MKV -vf "scale=640:360:force_original_aspect_ratio=decrease,pad=640:360:(ow-iw)/2:(oh-ih)/2" -acodec copy OUTPUT.MKV
Maybe someone will ask, why downgrade resolution to 640:360?
Beside for faster process, it will no differences if played in CRT-TV. But if you want to preserve resolution, then use original video source resolution (1280:720) or (1920:1080).
Reply




Users browsing this thread: 3 Guest(s)