Hello
I'd like to join two different videos into a single file, so that one movie with play before the second:
I naively used the following command, but the output file only includes the second file:Code:c:\>ffprobe.exe -i file1.mp4 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'file1.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf54.63.104 Duration: 00:03:28.69, start: 0.000000, bitrate: 815 kb/s Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 854x480 [SAR 1:1 DAR 427:240], 683 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default) Metadata: handler_name : SoundHandler c:\>ffprobe.exe -i file2.mpeg Input #0, mpeg, from 'file2.mpeg': Duration: 01:13:39.98, start: 0.604000, bitrate: 9356 kb/s Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv), 720x576 [SAR 64:45 DAR 16:9], max. 9100 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc Stream #0:1[0x80]: Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
Using ffmpeg, which solution would you recommend to concatenate those two files into one?Code:ffmpeg -i file1.mp4 -i file2.mpeg -c:v libx264 -r 25 -vf scale=640:-1 -pix_fmt yuv420p -c:a aac -strict experimental -b:a 128k -ac 2 -ar 44100 -threads 2 -crf 20 -f mp4 full.mp4
https://www.ffmpeg.org/faq.html#How-can-I-concatenate-video-files
Thank you.
---
Edit: I tried the following…
… but ffmpeg ain't happy:Code:ffmpeg -i file1.mp4 -i file1.mpeg -filter_complex "[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" -c:v libx264 -r 25 -vf scale=640:-1 -pix_fmt yuv420p -c:a aac -strict experimental -b:a 128k -ac 2 -ar 44100 -threads 2 -crf 20 -f mp4 output.mp4
Code:Filtergraph 'scale=640:-1' was specified through the -vf/-af/-filter option for output stream 0:0, which is fed from a complex filtergraph. -vf/-af/-filter and -filter_complex cannot be used together for the same stream.
+ Reply to Thread
Results 1 to 16 of 16
Thread
-
Last edited by yetanotherlogin; 12th Sep 2015 at 18:12.
-
You cannot "join" them as-is.
You must either conform the 2nd to the format of the 1st, or
conform the 1st to the format of the 2nd, or
conform both to a 3rd format to where they will have everything in common.
Only then can they be joined.
BTW, this is usually what's known as "editing".
Scott -
Thanks for the info.
Considering that the MP4 looks like this…
Code:Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 854x480 [SAR 1:1 DAR 427:240], 683 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default) Metadata:
Code:ffmpeg -i file2.mpeg -c:v libx264 -r 25 -vf scale=854:480 -c:a aac -strict experimental -b:a 128k -ac 2 -ar 44100 -threads 2 -crf 20 -f mp4 file2.mp4
Code:ffmpeg -i file1.mp4 -i file2.mp4 -filter_complex "[0:0] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" -c:v copy -c:a copy -threads 2 -crf 20 -f mp4 joined.mp4
Code:Streamcopy requested for output stream 0:0, which is fed from a complex filtergraph. Filtering and streamcopy cannot be used together.
Code:c:\>type input.txt file '.\file1.mp4' file '.\file2.mp4' c:\>ffmpeg -f concat -i input.txt -c copy joined.mp4
Code:[mp4 @ 041d2340] pts has no value DTS -406750706815049024, next:232370749 st:1 invalid dropping PTS -406750706815049024, next:232370749 invalid dropping st:1 DTS -118059162068766816, next:211979266 st:0 invalid dropping PTS -118059162068765792, next:211979266 invalid dropping st:0
Incidently, is there a command that tells ffmpeg to recompile a file by simply reading the settings of another file?
Thank you. -
MPEG Transport Stream as container may work for you. It is not recommended but also not forbidden.
-
It looks like MP4 is pretty much the standard these days, so I'd rather use that as a container.
https://en.wikipedia.org/wiki/MPEG_transport_stream
What do you guys use when you have to join two files that weren't encoded the same way? -
-
If the files have to be joined together in an mp4, I would re-encode one or both files so that they do match, like probably almost every else who answered you said to do, then concatenate them.
Even if you did manage to simply concatenate these two dissimilar files without re-encoding, media players in consumer electronics and software media players frequently don't correctly play dissimilar material that has been simply joined together in one file. -
Even if you match the exact same settings, the exact same encoder etc... it doesn't always work.
You can try other software like mp4box, mkvmerge to append segments, or retail smart encoding software like videoredo
It does increase your chances when using x264 if you use --stitchable in the commandline (not sure if it's available for libx264 in ffmpeg, but it would be under x264opts) or specify a different --sps-id . The 2nd method with a binary join always works when done properly (GOP boundaries). It's discussed in other threads
If this is the same as your other project, you should have done it in one operation which would work for sure (because joining is in the uncompressed domain, before encoding) .
You also have other problems (source was interlaced, but you didn't encoded interlaced, nor does it look like you bob deinterlaced) -
Thanks guys.
As a work-around, I re-encoded and compiled the two files into a single MP4 file using Corel VideoStudio, although I wish I could have used ffmpeg instead. It seems to take a bit of knowlege to join videos that weren't encoded the same way. -
Basically there are 2 methods I use to join files, Binary joining and ffmpeg concat. Different formats work with Concat and others work with binary.Checking several formats gave me these results:
FLV ffmpeg concat=joins OK plays both, length is both
FLV copy /b = 2 complete movies but time says only one and plays one
MKV ffmpeg concat=joins but first subtitle
MKV copy /b = 2 complete movies but time says only one and plays one
MP4 ffmpeg concat = joins but loses DVBsubs and srt subs
MP4 copy /b= 2 complete movies but time says only one and plays one
VOB ffmpeg concat = multiple errors trying to join and aborts
VOB /b works and carries over the DVD subtitles
3GP ffmpeg concat=joins/ plays fine Subtitles ??????
3GP copy /b = 2 complete movies but time says only one and plays one
FLAC ffmpeg concat= Multiple errors during conversion. Fails
FLAC copy /b = 2 complete movies but time says only one and plays one
MPG ffmpeg concat=joins/ plays fine. Gives correct time and size. Subtitles ??????
MPG copy /b = Seems to play ok but Time and size is given as only one video.
M2V = Same as MPG
M2V /b copy = Same as MPG
The formats for each are:
-
Thanks for the info.
Out of curiosity, what's that Media Utility software? It's drowned in hits when googling for it. -
Media Utility is a program I wrote(am writing as ongoing project.) I got tired of looking up something that I have looked up before but couldn't remember how. It spits out the format for MANY of the requests people ask for that are unique maybe to them and several others. I'm sure it could use improved but it does most of what I want:
1. Check integrity of FLV videos
2. Remove Meta Data
3. Replace Meta Data
4. Perform Media Info on the video for most needed information with Media Info CLI
(https://mediaarea.net/en/MediaInfo/Download/Windows)
5. Extract Audio
6. Extract Video
7. Shift Audio/Video to resync (Can visually compare audio to video)
8. Rename Videos with Media Info in name
9. Find old video names left coded into the video
10. Player using your main viewer for videos
11. Built in Windows Media Player
12. Embed the date/time from the image. Not the Windows file data but the data from the camera
13. Add a subtitle track to an MP4 or MKV OR Hardcode subtitles into a video (SRT/ASS at the moment)
14. Add logo
15. Add overlay (picture in Picture)
16. Calculator
17. Histograms (Including Quality difference [work in progress])
18. One image converted to video so plays music with single image
19. Multiple images slideshow while playing audio(with or without transitions between)
20. Crop and pad Landscape/Portrait to create Portrait/Landscape so it can be used with others in 19 above
21. Merge Resize
22. Edit video with size, quality, aspect, crop, pad, brightness, contrast, intensity, RGB color saturation
23. RECENT added changing Created/modified date/time FROM Encoded/Tagged date/time or TO Encoded Date/time
I use it to post an answer that can be proven is seconds to work so the information is correct for those that request help. -
Thanks for the info.
But again: What tool do you guys use to to convert different videos into the same format, before joining them?
To get back to the actual files I had to deal with: Provided ffmpeg can be used for that, what switches would you use to re-encode the MPEG file to match the MP4 file?
Code:c:\>ffprobe.exe -i file1.mp4 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'file1.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf54.63.104 Duration: 00:03:28.69, start: 0.000000, bitrate: 815 kb/s Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 854x480 [SAR 1:1 DAR 427:240], 683 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default) Metadata: handler_name : SoundHandler c:\>ffprobe.exe -i file2.mpeg Input #0, mpeg, from 'file2.mpeg': Duration: 01:13:39.98, start: 0.604000, bitrate: 9356 kb/s Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p(tv), 720x576 [SAR 64:45 DAR 16:9], max. 9100 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc Stream #0:1[0x80]: Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
-
Just for the record here... It is very difficult to encode a video to match another mp4 but not impossible. It is so hard that I created a program to create the string for me. The 2 files are almost exactly the same format and join so that they play all the way through without problems.. I have tried it other ways but some videos worked and some didn't. Haven't had a problem now so far using most of the second videos parameters.
EXAMPLE:
Code:ffmpeg -i "C:\Users\Bud\Desktop\Wham_Last Christmas.mp4" -ss 102.700000 -vframes 250 -c:v libx264 -b:v 873k -crf 20 -r 30 -profile High -level 3 -preset medium -c:a aac -ar 44100 -ab 128k -x264-params cabac=1:refs=4:deblock=1:0:0:analyse=0x3:0x113:me=hex:subme=7:psy=1:psy-rd=1.00:0.00:mixed-refs=1:me-range=16:chroma-me=1:trellis=1:8x8dct=1:cqpfile=0:deadzone=21,11:fast-pskip=1:chromaoffset=-2:threads=18:lookahead-threads=2:sliced-threads=0:nr=0:decimate=1:interlaced=0:bluray-compat=0:constrained-intra=0:bframes=3:b-pyramid=0:b-adapt=1:b-bias=0:directpred=1:weightb=1:open-gop=0:weightp=2:keyint=250:min-keyint=25:scenecut=40:intra-refresh=0:rc-lookahead=40:rc=crf:mbtree=1:crf=1.0:qcomp=0.60:qpmin=0:qpmax=69:qpstep=4:ip-ratio=1.40:aq-mode=1:crf=20.0 -refs 4 -y "C:\Users\Bud\Desktop\T1_0_Wham_Last Christmas.mp4"
Similar Threads
-
how to join video files pls ?
By erzane in forum Newbie / General discussionsReplies: 30Last Post: 16th Sep 2014, 14:01 -
Question how to join these 2 video files
By jimdagys in forum EditingReplies: 2Last Post: 16th Dec 2013, 04:17 -
Trying to join 12 video files together
By tater259 in forum EditingReplies: 12Last Post: 9th Feb 2013, 12:48 -
How to join four .flv files in to one .flv file using ffmpeg?
By spiderMan007 in forum EditingReplies: 3Last Post: 26th Aug 2012, 13:18 -
Video Files, join video_ts and flash video
By Pumkinhead in forum Newbie / General discussionsReplies: 2Last Post: 6th Feb 2011, 06:45