# How to join Videos Ffmpeg?

1. Hi VideoHelp community,

Here is my problem and hope someone help me to solve this.

So i have some files like video1.mp4 video1.ass video2.mp4 video2.ass ... , i need to hardsub video1.ass in video1.mp4 and cut video1.mp4 with a start and end time,
and i need to do this for every video and sub, and finally join the created files.
Can i do this with one command in ffmpeg? If not, how to save all created files with same parameters then to use the ffmpeg concat withour reencoding, or how to
merge video files with different video parameters. Thanks anyway.
2. Hardsub implies reencoding. Merging video files with different video parameters also most likely involves reencoding.
Perhaps it would be easier to do with an Avisynth script.

Something like :
Code:
V1 = DirectShowSource("video1.mp4").TextSub("video1.ass").Trim(50,3500) # cuts video1.mp4 from frame 50 to frame 3500
V2 = DirectShowSource("video2.mp4").TextSub("video2.ass").Trim(0,2800) # cuts video2.mp4 from the first frame (frame count starts from 0) to frame 2800
V3 = DirectShowSource("video3.mp4").TextSub("video3.ass").Trim(800,0) # cuts video3.mp4 from frame 800 to the end
V1 ++ V2 ++ V3
Then save this as an AVS script (just a text file with a .avs extension), named for instance "V1 + V2 + V3.avs", and run the encode with ffmpeg, using the AVS script as input :
Code:
ffmpeg -i "V1 + V2 + V3.avs" -c:v libx264 -crf 20 -preset slower -c:a aac "V1 + V2 + V3.mp4"
You could perhaps cut/join the audio losslessly and then pass it through but it gets more complicated. You could also encode the audio separately using a better quality encoder like qaac, and then pass it through.
Code:
ffmpeg -i "V1 + V2 + V3.avs" -vn -f wav - | qaac - -o "V1 + V2 + V3.m4a"
ffmpeg -i "V1 + V2 + V3.avs" -i "V1 + V2 + V3.m4a" -map 0:0 -map 1:0 -c:v libx264 -crf 20 -preset slower -c:a copy "V1 + V2 + V3.mp4"
3. Originally Posted by abolibibelot
Hardsub implies reencoding. Merging video files with different video parameters also most likely involves reencoding.
Perhaps it would be easier to do with an Avisynth script.

Something like :
Code:
V1 = DirectShowSource("video1.mp4").TextSub("video1.ass").Trim(50,3500) # cuts video1.mp4 from frame 50 to frame 3500
V2 = DirectShowSource("video2.mp4").TextSub("video2.ass").Trim(0,2800) # cuts video2.mp4 from the first frame (frame count starts from 0) to frame 2800
V3 = DirectShowSource("video3.mp4").TextSub("video3.ass").Trim(800,0) # cuts video3.mp4 from frame 800 to the end
V1 ++ V2 ++ V3
Then save this as an AVS script (just a text file with a .avs extension), named for instance "V1 + V2 + V3.avs", and run the encode with ffmpeg, using the AVS script as input :
Code:
ffmpeg -i "V1 + V2 + V3.avs" -c:v libx264 -crf 20 -preset slower -c:a aac "V1 + V2 + V3.mp4"
You could perhaps cut/join the audio losslessly and then pass it through but it gets more complicated. You could also encode the audio separately using a better quality encoder like qaac, and then pass it through.
Code:
ffmpeg -i "V1 + V2 + V3.avs" -vn -f wav - | qaac - -o "V1 + V2 + V3.m4a"
ffmpeg -i "V1 + V2 + V3.avs" -i "V1 + V2 + V3.m4a" -map 0:0 -map 1:0 -c:v libx264 -crf 20 -preset slower -c:a copy "V1 + V2 + V3.mp4"
Thanks a lot, i will try this and see if it helps.
4. How to set same framerate and resolution?
5. Well, I'm not that far ahead of the beginner level when it comes to the highly intricate world of Avisynth, so I could hardly provide specific tips relevant to a specific situation, beyond what's available on general information pages... But admittedly information is scarce and can be confusing from a complete newbie's point of view.
I'm currently working on a script which you can find here, and which could help you to get a broad picture of how to achieve what you wish to achieve.
There are several ways to convert the framerate in Avisynth. ChangeFPS() simply duplicates or removes frames (it's the most simple and the fastest method but can cause some stuttering / jerkiness on scenes with constant motion), ConvertFPS() blends frames (may improve motion smoothness but blended still frames may look weird), MFlowFPS() interpolates frames (much more complex and therefore slower, can look much better but can also produce ugly artifacts).
There are also several ways to convert the resolution, with a slightly different result, some sharper, some softer (sharpness is generally considered beneficial but it can also add artifacts). I generally use BicubicResize, which seems to be considered a good compromize, but it may not be the best suited for every case.
For instance ChangeFPS(30000,1001) will convert the framerate to 29.97 FPS (30000 divided by 1001), and BicubicResize(1280,720) will convert the resolution to 1280x720.
With AVSPMod you can edit the script with some helpful tips and preview the result right away.

The DirectShowSource() import filter I used in the example above is known to have reliability issues (see “jagabo”'s reply in the thread linked above). I'm not sure which one to recommend with MP4 sources, let's hope someone more experienced chimes in. As far as I know, other filters (except AVISource which doesn't work with MP4 sources) import video and audio separately, which complicates the script (import video, import audio, then mix video and audio with AudioDub), that's why I used DirectShowSource here to provide a relatively simple example.

In this other example, the source files are imported with LSMASHVideoSource / LSMASHAudioSource, with added framarate and resolution conversions, plus a fade-in and a fade-out. It requires the L-SMASH plugin (either put the DLL in the Avisynth Plugins directory, or specify its path at the beginning of the script with LoadPlugin, as below). If the source files are not in the same directory as the script, their complete path must be specified.
Code:
LoadPlugin("C:\path\to\lsmash\LSMASHSource.dll")
V1v = LSMASHVideoSource("video1.mp4")
V1a = LSMASHAudioSource("video1.mp4")
V1 ++ V2 ++ V3