VideoHelp Forum
+ Reply to Thread
Results 1 to 10 of 10
Thread
  1. I found this thread about batch processing ffmpeg for stabilizing the videos. But I had some questions, but the forum suggested makign a new thread instead of posting in the old one. So here it is.

    Originally Posted by racer-x View Post
    I just learned of the Stabilize filter in ffmpeg. I created one that will batch stabilize all MOV's in a folder. Just change input extension in lines 2 and 3 for other types. It's an automated two-step process that first analyses, then processes using codec of choice. It's almost as good as the DeShaker plugin for Virtualdub, but it also has advantages over it like batch processing.

    To use, you'll need latest version of ffmpeg 32 or 64 bit. You'll need to edit the Path to ffmpeg in the first line. Change the input extensions as needed in lines 2 and 3. Then just drag first clip into the batch file and all will be processed.

    Along with the newly created clips, it will produce RTF files (processing information) and a Dummy.avi that shows tracking markers. You can delete these when finished.

    Here is a script that should work OK with most shaky footage:
    Code:
    SET PATH="E:\Backup\Video Apps\Video Encoders\FFmpeg\FFMpeg\64-bit"
    for %%a in ("*.mov") do ffmpeg -i %%a -vf vidstabdetect=shakiness=10:accuracy=15:result="%%~na.trf":show=1 dummy.avi -y
    for %%a in ("*.mov") do ffmpeg -i %%a -vf vidstabtransform=crop=black:input="%%~na.trf" -c:v libx264 -level 41 -pix_fmt yuv420p -g 24 -crf 19 -c:a aac -strict experimental -ar 48000 -ab 256k -f mp4 "%%~na_stab.mp4"
    
    pause
    Here is an example of results:


    How does this work? How do I specify which folder my mp4 files to be stabilized are?

    and if we go with selur's suggestion, will the code look like below?


    Code:
    SET PATH="E:\Backup\Video Apps\Video Encoders\FFmpeg\FFMpeg\64-bit"
    for %%a in ("*.mov") do ffmpeg -i %%a -vf vidstabdetect=shakiness=10:accuracy=15:result="%%~na.trf":show=1 -an  -f null  NUL
    for %%a in ("*.mov") do ffmpeg -i %%a -vf vidstabtransform=crop=black:input="%%~na.trf" -c:v libx264 -level 41 -pix_fmt yuv420p -g 24 -crf 19 -c:a aac -strict experimental -ar 48000 -ab 256k -f mp4 "%%~na_stab.mp4"
    
    pause

    if I wanted to stabilize a bunch of mp4s, then will the code look like


    Code:
    SET PATH="E:\Backup\Video Apps\Video Encoders\FFmpeg\FFMpeg\64-bit"
    for %%a in ("*.mp4") do ffmpeg -i %%a -vf vidstabdetect=shakiness=10:accuracy=15:result="%%~na.trf":show=1 -an  -f null  NUL
    for %%a in ("*.mp4") do ffmpeg -i %%a -vf vidstabtransform=crop=black:input="%%~na.trf" -c:v libx264 -level 41 -pix_fmt yuv420p -g 24 -crf 19 -c:a aac -strict experimental -ar 48000 -ab 256k -f mp4 "%%~na_stab.mp4"
    
    pause
    How will the resulting files be neamed? Same as the original? But won't that overwrite the original? Or will it prompt the replace or keep eveyrtime it converts a file?

    I need some help please.
    Quote Quote  
  2. Originally Posted by seanincali View Post


    How does this work? How do I specify which folder my mp4 files to be stabilized are?

    How will the resulting files be neamed? Same as the original? But won't that overwrite the original? Or will it prompt the replace or keep eveyrtime it converts a file?
    The way that is written, you place the .bat file in the same folder of files to be converted, then double click to execute . All .mov files will be processed in the folder. The output files will be placed in the same directory, with same filenames but "_stab" appended at the end of filename and mp4 container. Original files will not be overwritten as they have different filename and extension. But some people like to use other directories or better yet drives (faster to read/write to different physical drives, and safer)

    If you wanted to specify a different directory, you can add it to the end instead of
    Code:
    "%%~na_stab.mp4"
    it would be
    Code:
    "PATH\%%~na_stab.mp4"
    where PATH is the actual directory path
    Quote Quote  
  3. Thank you for the reply. It makes sense now. I'm off to test this out. I'll be back if my laptop doesn't blow up. Wish me luck!
    Quote Quote  
  4. Ok. I've tried it out with the following code.

    Code:
    SET PATH="C:\ffmpeg\bin"
    
    for %%a in ("*.mp4") do ffmpeg -i %%a -vf vidstabdetect=shakiness=10:accuracy=15:result="%%~na.trf":show=1 -an  -f null  NUL
    
    for %%a in ("*.mp4") do ffmpeg -i %%a -vf vidstabtransform=crop=black:input="%%~na.trf" -c:v libx264 -level 41 -pix_fmt yuv420p -g 24 -crf 19 -c:a aac -strict experimental -ar 48000 -ab 256k -f mp4 "C:\temp\%%~na_st.mp4"
    
    
    pause

    And it's giving me error because of the white spaces. I can rename all the file, but is there a way to script that in there?

    Also how will I strip the metadata from the file as the stabilization ends? I found this code from superuserhttps://superuser.com/questions/441361/strip-metadata-from-all-formats-with-ffmpeg

    Where thwy suggested the following

    Code:
    ffmpeg -i in.mov -map_metadata -1 -c:v copy -c:a copy out.mov
    So if I do the following, will that work?

    Code:
    SET PATH="C:\ffmpeg\bin"
    
    for %%a in ("*.mp4") do ffmpeg -i %%a -vf vidstabdetect=shakiness=10:accuracy=15:result="%%~na.trf":show=1 -an  -f null  NUL
    
    for %%a in ("*.mp4") do ffmpeg -i %%a -vf vidstabtransform=crop=black:input="%%~na.trf" -c:v libx264 -level 41 -pix_fmt yuv420p -g 24 -crf 19 -c:a aac -strict experimental -ar 48000 -ab 256k -f mp4 "C:\temp\%%~na_st.mp4"
    
    for %%a in ("*.mp4") do ffmpeg -i %%a -map_metadata -1 -c:v copy -c:a copy %%~na_st.mp4
    
    
    pause
    Quote Quote  
  5. Originally Posted by seanincali View Post
    And it's giving me error because of the white spaces. I can rename all the file, but is there a way to script that in there?
    put the input %%a in quotation marks

    Code:
    SET PATH="C:\ffmpeg\bin"
    
    for %%a in ("*.mp4") do ffmpeg -i "%%a" -vf vidstabdetect=shakiness=10:accuracy=15:result="%%~na.trf":show=1 -an  -f null  NUL
    
    for %%a in ("*.mp4") do ffmpeg -i "%%a" -vf vidstabtransform=crop=black:input="%%~na.trf" -c:v libx264 -level 41 -pix_fmt yuv420p -g 24 -crf 19 -c:a aac -strict experimental -ar 48000 -ab 256k -f mp4 "C:\temp\%%~na_st.mp4"
    
    
    pause

    Originally Posted by seanincali View Post
    Also how will I strip the metadata from the file as the stabilization ends?
    which metadata are you referring to exactly ?
    Quote Quote  
  6. Ah ok. " %%a" it is then.



    by metadata, I mean title, author, comment, encoder, and date etc. I'd like strip them all of private information. Since the file aklready has the title, no other information is needed for me.


    And it seems the ffmpeg stabilization results in much bigger file that I would normally get from within virtual dub. Has anyone noticed this?
    Quote Quote  
  7. Originally Posted by seanincali View Post
    by metadata, I mean title, author, comment, encoder, and date etc. I'd like strip them all of private information. Since the file aklready has the title, no other information is needed for me.
    When you re-encode, all those values will be overwritten anyways. But ffmpeg can only access some of the fields, not all. Some other ones might be accessible by exiftool. MetaX (not free) is another for MP4 container. You don't "save" any filesize by stripping metadata (it's negligible), most people don't bother .

    And it seems the ffmpeg stabilization results in much bigger file that I would normally get from within virtual dub. Has anyone noticed this?
    This has more to do with your encoding settings or differences. In your (or I guess racer-x's) batch file, you have -g 24, which means a max keyframe interval of 24. Default is 250. In general, the larger the value, the higher the compression, the smaller the filesize (with diminishing returns) for a given set of settings. You're using -crf 19 (higher values yield lower quality, smaller filesizes) . Also, if you used deshaker in vdub, you might have used different stabilization. A more stable video will result in smaller filesizes if everything else was the same. So even if you matched the encoding settings, it's not really an "apples to apples" comparison
    Quote Quote  
  8. I see. ok Thank you so much for the help.
    Quote Quote  
  9. Originally Posted by poisondeathray View Post
    Originally Posted by seanincali View Post
    by metadata, I mean title, author, comment, encoder, and date etc. I'd like strip them all of private information. Since the file aklready has the title, no other information is needed for me.
    When you re-encode, all those values will be overwritten anyways. But ffmpeg can only access some of the fields, not all. Some other ones might be accessible by exiftool. MetaX (not free) is another for MP4 container. You don't "save" any filesize by stripping metadata (it's negligible), most people don't bother .

    And it seems the ffmpeg stabilization results in much bigger file that I would normally get from within virtual dub. Has anyone noticed this?
    This has more to do with your encoding settings or differences. In your (or I guess racer-x's) batch file, you have -g 24, which means a max keyframe interval of 24. Default is 250. In general, the larger the value, the higher the compression, the smaller the filesize (with diminishing returns) for a given set of settings. You're using -crf 19 (higher values yield lower quality, smaller filesizes) . Also, if you used deshaker in vdub, you might have used different stabilization. A more stable video will result in smaller filesizes if everything else was the same. So even if you matched the encoding settings, it's not really an "apples to apples" comparison
    if I can bother you with more question related to this...

    i think I prefer VD's shaker than this ffmpeg version, and i was wondering if you have a way to process mutiple mp4 files ina folder using batch process in virtualdub.

    I think job control and other functions in virtualdub can be helpful, but I just can't figure out.

    I did manage to batch produce avs files in a folder for each mp4s i want to process. It's to direct show the mp4's in virtual dub instead of having to convert them to avi files.

    Now I just need a way to use the same setting on the deshaker filter and run video analysis, deshake, and then export as mp4s using external encoder.

    I was trying to setup windows macro programs to do it, but I'm not having much luck in that dept either.

    Can you suggest something to accomplish what I am trying to do here?
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!