Menu

#308 How does Export Stream Copy work?

open
nobody
None
question
2020-04-10
2020-03-03
Anonymous
No

Hi,

so I have a question about the export stream copy process.Could you explain what it exactly does to output the new video file?I mean, what would be the commandline paramters for FFmpeg if I wanna do the same just using FFmpeg manually?

I found a problem during using FFmpeg to record a HLS stream just using - copy mode and -f mpegts or mp4 format container.So as results I get a recorded file where the first 20 frames are just same before the video runs normaly.I found out that the problem is the audio stream which is a little longer than the video stream.In this case the audio stream starts first for 20 video frames (same frames) and after this starts the video correcly.I didnt found a FFmpeg command yet to prevent this problem.When I play those files with VLC or other players then I can see it too that the video hangs for a short while but audio is playing already.

Now I have my problem files and when I load them into VD2 then I get 2 diffrent conditions.
1.) VD2 does also show the first 20 frames as same frames or
2.) VD2 does show frames correctly from beginning and does also play them right (what not happens in VLC and audio plays first for a moment before video stream runs).VD2 did already cut away the audio at the start on loading.

Now when I just use the export stream copy mode in VD2 to export the same video without re-encoding then the video is somehow fixed and VLC does also play them correctly from the start without to hang for a moment.So I see that the stream copy mode seems to work diffrent to the copy mode of FFmpeg when I do use it manually.In the case of using stream copy mode in VD2 it does cut away the audio at the beginning and thats good of course and video/audio streams starting correctly.

Below a example: First one is original file I tried to fix with FFmpeg & VD2

RecordedFile:       duration= 29.120s 
                                          audio duration= 29.824s
                                          mpegts  <-- original record with ffmpeg

RecordedFile:       duration= 29.320s 
                                          audio duration= 29.994s
                                          mp4     <-- used -c copy -f mp4 with ffmpeg

RecordedFile:       duration= 29.200s
                                         audio duration= 29.269s
                                         mp4     <-- used export stream copy mode in VD2

So you can see the diffrents in the duration lenghts.The original file has a overlenght of almost 1 second which happens at the beginning (not at end).Now when I was using FFmpeg in copy mode + setting mp4 container then its just adding a lenght of 0.200s to duration and 0.120s to audio duration and problem isnt fixed.In the case of using VD2 the audio duration gets cutted away so that both lenghts match very good.So my question is how VD2 does export the video to fix those overhead audio lenghts from the beginning and how can I do this manually using FFmpeg?So is there a way to fix such files just using FFmpeg CLI alone (when I start a recoed & or after to fix such files) or have I always to use VD2 in such cases and make this export stream copy?Of course a detour doing that and I would like to prevent this step.Maybe you can help with some infos about it.

PS: One info about using export stream copy mode.So it still dosent work correctly when I crop or cut video parts by keyframes and output selected part by keyframe = wrong output file.Its only working correctly when I select any area by keyframe to output this part + keeping video untouched from crop / cut etc using input driver.So if I wanna cut out more than 1 video parts by keyframe then I have to do this one by one and mux them together later.So I cant do this directly in VD2 = detour.

Question or Request: So is there any option to see the selected duration?Lets say I wanna select one minute in video but I dont see any selected time how much I did selected already.In the time format choice I cant find any what could do this.So if VD2 hasnt such option to show the time of selection then you could maybe add this too in a next version.

Thank you

Discussion

  • Anton Shekhovtsov

    About selected duration: correct, I can add it to the status bar.
    If you need selection of given lenght you can do this: from start of selection press "Go to frame..." type in "time" field +1m.

     
  • Anton Shekhovtsov

    I cant tell exactly in terms of command line beause it is not done like that.
    Basically I implement seek to the end of selected range, remember which packets appear after it, then seek to the start of selected range, and copy av packets until I meet the remembered end packets. Also offset timestamps in the process.
    Probably, the only thing relevant to your question is the seeking. Try to specify start offset to match the first video keyframe. I dont know how to specify this with command line, maybe this can work ffmpeg -ss 0 -i input.mts or this ffmpeg -ss 00:00:00.1 -i input.mts. Actually, because video timestamps may begin from any number, you may need to find out that value (ffmpeg is very vague in determining where the thing begins).

     
  • Anonymous

    Anonymous - 2020-03-04

    Hi Anton,

    thanks for your answer so far.Yes it would be very nice if you could add the selected duration time stamp into status bar like this 0:00:11.360.

    Thanks for the info about +/- jumper from selection position.I didnt know that before but good to know now.

    About the -ss command.So this seems to work to get the audio at the start cutted away without to re-encode.Just bad that I can't use any command of FFmpeg during a record to get this fixed or preventing = need to re-fix recorded file after.

    So I have another question about cutting videos so maybe you have any hints for me.The problem is when I do cut a video in diffrent parts (maybe 5) from somewhere in the video then the new parts have mostly not the same audio duration of video duration stream so they differ (anyway whether I do encode new or just cut by keyframes).Mostly audio duration is a little longer.When I do run / watch every single cutted part alone then all is fine and audio does match to video (checking this when people do talk in video) but when I now do mux all parts (5 or many more) together then I got trouble with the new video and audio stream dosent match anymore to video stream = audio is getting ahead or back (people in video talking but audio comes to late etc you know).So how can I prevent this problem to get at the end a matching result to get a 1A match?

    Thank you

     
    • Anton Shekhovtsov

      Is this question about ffmpeg?
      I'm not sure how ffmpeg joins files. Maybe you can get better accuracy if you save intermediate pieces with pcm audio.
      Also maybe you can split and join pieces using mkvmerge, I think it deals with av sync.

       
    • Anton Shekhovtsov

      Added duration in build 44282
      The format depends on current preference (also accessible from position context menu)

       
  • Anonymous

    Anonymous - 2020-04-08

    Hi Anton,

    thank you for adding the select time feature in latest version.

    So I have some more questions using VD2 and the DirectStreamCopy function (Not export stream).I know its not working to use it when loading a video with CacheInputDriver but why does the DirectStreamCopy mode also does fail when I load video with other driver like QuickTime or FLV.....if I change the audio stream?

    Example: I load a MP4 container video using QuickTime driver into VD2.Now if I select DirectCopyStream for video & audio and choose save video from menu (F7) then I can also see both stream copy modes for video & audio and I can save the video (only with AVI container).When I now just set the audio source to a extern audio file I do load and press F7 then I see that the audio stream wants to saved as PCM with no compression.The question why?So I am using not the CacheInputDriver.Normaly it should work to save the audio stream to if I have changed it like it does in VD1 too.Maybe you can exlpain that why its not working and why I have to switch to VD1 in that case.If use VD1 in that case is also not best because I can only save the new file in AVI container.Anyway, problem is that I can't work completely alone with VD1 / VD2.Maybe you can do work something more for that direct stream issues VD2 has.

    Another question I have again about cropping.I am still missing a aspect ratio selection cropper and need to calc the exactly matching widh & height manually using a calc to crop something specially in a zoomed aera.Thats bad of course.Maybe you can put this onto your todo agenda for next update (4:3,16:9,21:9 etc).Now if you say I should use the cropper from resize filter then I can see its limited to crop only the whole video and just the middle crop selection (otherwise I need some fiilter handling before = detour work and I hate detours).So if this isnt possible for you to do this then it would be maybe a good idea to show a realtime calculator on the "Filter Input Cropping" window what shows the calc values....

    Example: Lets say I have loaded a video 854x480 = 16:9 AR.Now I have added a NULL filter and open the cropping window and do select the area I want to crop but of course I want to crop with a exactly aspect ratio format.Now imaginge I did select a aera which starts with the top height of 300 to start the cropping from this position.Now I need also to know the matching width I need to use for 300 for a desired AR format I wanna have and I need to calc this out manually (= Bad & time waste).My idea is that you just show it in realtime like you also do show the select w&h values.So in this example where we have height of 300 you can use this value and doing a calc on fly and VD2 should show the right matching width for this height which would be 533 for 16:9 or 400 for 4:3 AR.Do you know what I mean Anton?Also the same with the width if the user does move it so just calc the ARs in realtime out and show it to the user.In my case I coded a small AR calculator for myself to do this using float commands but would better to have this in VD2 itself of course.Maybe you can do something for this.

    One more.Big problem is still the handling of files with MPEG-TS container loading them into VD2 using CacheInputDriver.Maybe frames are grayed to see if moving the slider for / back so I told this too before already.Maybe you could think about it again to add a option in your CacheInputDriver to load MPEG-TS files in a MPEG-4 container on fly during loading the video into VD2.This would be very helpfully and the video would shown for 100% correctly without grayed frames on moving.Just do the same as you do on saving when I can choose the diffrent container formats.Just add something like this for loading (in my case I just need to load MPEG-TS files).So why I am asking about it you may ask.I do record just in MPEG-TS container using FFmpeg because its working for 100% percent.When I do same using MP4 container to record something then its not working for 100% and maybe just for 90%.Some records do just fail with that container whats really bad of course.Thats why I have to use MPEG-TS instead = I get what I do record.The disadvantage is that I need to edit those files and put them into MP4 container later = detour.
    1.) I did record a file in MPEG-TS.
    2.) I load this file in VD2 = showing bad / grayed = bad to edit
    3.) I need to give the file a MP4 container using FFmpeg CLI = new file
    4.) Now I can load this new file in VD2 to edit it etc.

    Diffrent detour steps I would like to prevent of course.First problem is that FFmpeg dosent work for 100% using MP4 container as I told above.Also not when I am using something like...
    -movflags +faststart.In this case its also not possible to check the record on fly like its possible with MPEG-TS.No clue why there are some wrong infos about that in the internet to find.Maybe wrong theme at the moment to talk about that.It would be nice if you could add such a feature to load video files (specially TS) in a other container.

    I think thats all for the moment Anton.Thank you.

    greetz

     
    • Anton Shekhovtsov

      Hi,
      1) When you select "audio from other file" there is also input driver selection. This is another file with another driver.
      2) Adding AR math: maybe.
      3) mts support. The only way to fix it is to fix it. Maybe one day. I don't know why "open a file as another container on fly" sounds like quick solution to you.

       
  • Anonymous

    Anonymous - 2020-04-10

    Hi Anton,

    ahh ok so now I do see this too.There is also a choosable driver menu.Ok,sorry about that so it seems to work ok now if I do choose the other driver and to get also streamcopy mode for that audio if I wanna save it.

    Yes, adding a AR would be nice if possible.

    So the mts handling isnt pretty nice using VD2 with your CIP because it dosent decode all frames correctly on fly as you told me already before.In this case its also bad to re-encode some video parts new so it can have those grayed frames inside the new video = I dont wanna have of course.Also happens if I do not re-encode and just using export stream with some selected key frame parts.Mostly in this case the first keyframe area is grayed in the exported video.Then I need to re-load this new video into VD2 / CIP and cut aways this first keyframe and export the video again = fine now.This process sucks to do those steps twice.Loading those mts video with a MPEG-4 container on fly in VD2 / CIP would be great.Then I could edit video normaly without having any grayed frames on seeking and re-encode or just exporting.Just think about that and play around with some mts files.So on the other hand you also export those mts files with a MPEG-4 container and not again with a MPEG-TS container.Why not doing the same on loading too?Just if the user wants this of course.Maybe you can check this out a little to see whats possible in that case.

    Ok Anton, so I have one more little question so I hope you dont mind if I ask here again without to create a new ticket.So I have a problem with some video files which are shown not correctly.

    Example: I have a FLV / AVC video (container not important in that case) and the video look strange when playing it in VLC or MPC-HC etc.So the lower side of the video is looking like mud or the half lower side is just green.This green thing I get to see in VD if I use the FLV plugin to load it in VD.Upper side is correctly shown but lower side is all green.In player itself I just see this more in black mud style or whole video is bad showing like this.Now on internet I found some infos to disable hardware decoding in VLC and I tried this out and it works.The video is shown fine for 100%.Problem is that I wanna just disable / enable the hardware decoding if I wanna watch such movie you know.In VLC I have set this option to auto.Now listen, when I load such a bad video in VD2 using CIP or ffmpeg driver then this video is shown correctly what is good so far.Now I can edit the video etc but if I export some video parts or just re-encode a part to new file then this problem is still present in the new video.Thats bad of course.Now my questions about this...

    1.) How can I load such a video with FLV plugin in VD2 without getting those half green screen to see?Can I setup something in VD setting or so?Nothing found about hardware decoding there etc.

    2.) Re-Encode seems to work using CIP or ffmpeg but both driver have problems.CIP is showing a wrong framerate 1000+/- instead of 29.9.FFmpeg driver shows right framerate but has any issues to show all frame at the end (many frames are just same).So with both drivers I get bad results with those files.But also just using ffmpeg CLI tool alone to re-encode also dosent work fine and new video has a framerate of 1000 too.But listen, when I change the container format from FLV to MP4 then both driver do read the file with the right framerate into VD2 = good.Also ffmpeg CLI itself works fine in that case.

    All in all there are always some issue specially with that container handling.Having a option to load videos with a desired container would be a "must have" so I think.Would save much de-tour handling and prevent creating many temporary new files (HDD / SSD life).

    Hints are welcome of course.

    Bye

     

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB