VideoHelp Forum

+ Reply to Thread
Results 1 to 16 of 16
Thread
  1. Member
    Join Date
    Mar 2011
    Location
    Paris, France
    Search PM
    Hello

    I'd like to join two different videos into a single file, so that one movie with play before the second:

    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
    I naively used the following command, but the output file only includes the second file:
    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
    Using ffmpeg, which solution would you recommend to concatenate those two files into one?
    https://www.ffmpeg.org/faq.html#How-can-I-concatenate-video-files

    Thank you.

    ---
    Edit: I tried the following…
    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
    … but ffmpeg ain't happy:
    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.
    Last edited by yetanotherlogin; 12th Sep 2015 at 19:12.
    Quote Quote  
  2. Member Cornucopia's Avatar
    Join Date
    Oct 2001
    Location
    Deep in the Heart of Texas
    Search PM
    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
    Quote Quote  
  3. Member
    Join Date
    Mar 2011
    Location
    Paris, France
    Search PM
    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:
    … I tried recompiling the MPEG file thusly:
    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
    Next I used the following to join them:
    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
    … but no go:
    Code:
    Streamcopy requested for output stream 0:0, which is fed from a complex filtergraph. Filtering and streamcopy cannot be used together.
    Next, I tried the following:
    Code:
    c:\>type input.txt
    
    file '.\file1.mp4'
    file '.\file2.mp4'
    
    c:\>ffmpeg -f concat -i input.txt -c copy joined.mp4
    … but it's not working either, as ffmpeg barfs out millions of lines like this:
    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
    Any idea what I'm doing wrong?

    Incidently, is there a command that tells ffmpeg to recompile a file by simply reading the settings of another file?

    Thank you.
    Quote Quote  
  4. I'm a MEGA Super Moderator Baldrick's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Search Comp PM
    I don't think you can do this in one step. You must first convert it with exact same settings(no, ffmpeg can't read the settings from another file).
    Quote Quote  
  5. MPEG Transport Stream as container may work for you. It is not recommended but also not forbidden.
    Quote Quote  
  6. Member
    Join Date
    Mar 2011
    Location
    Paris, France
    Search PM
    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?
    Quote Quote  
  7. Originally Posted by yetanotherlogin View Post
    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?

    Well... TS is standard and it is widely used from over 20 years and it support concatenating of the different codecs by definition.
    Quote Quote  
  8. Member
    Join Date
    Aug 2006
    Location
    United States
    Search Comp PM
    Originally Posted by yetanotherlogin View Post
    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.
    Quote Quote  
  9. 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)
    Quote Quote  
  10. Member
    Join Date
    Mar 2011
    Location
    Paris, France
    Search PM
    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.
    Quote Quote  
  11. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    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:
    Click image for larger version

Name:	ScreenHunter_164 Sep. 14 09.56.jpg
Views:	1252
Size:	118.1 KB
ID:	33658
    Click image for larger version

Name:	ScreenHunter_164 Sep. 14 09.59.jpg
Views:	1133
Size:	118.0 KB
ID:	33659
    Quote Quote  
  12. Member
    Join Date
    Mar 2011
    Location
    Paris, France
    Search PM
    Thanks for the info.

    Out of curiosity, what's that Media Utility software? It's drowned in hits when googling for it.
    Quote Quote  
  13. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    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.
    Quote Quote  
  14. Member
    Join Date
    Mar 2011
    Location
    Paris, France
    Search PM
    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
    Quote Quote  
  15. Another command i have found is:
    Code:
    ffmpeg -i vid1.mp4 -i vid2.mp4 -filter_complex "[1:v][0:v]scale2ref=oh*mdar:h=in_h:[v1][v0];[v0][v1]hstack[vo]" -map "[vo]" ./output-video.mp4
    (2nd video scale to match the 1st)
    source
    Quote Quote  
  16. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    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"
    Quote Quote