VideoHelp Forum




+ Reply to Thread
Results 1 to 6 of 6
  1. Hi all,

    I would like to know if somebody could help me to translate this Avisynth script to ffmpeg.

    Basically it is about to divide each video selecting its central third part (cropping it), and putting together that cropped area side by side alongside the same area from the other video. This gives us a good visual comparison.

    In summary it's about the traditional side by side comparison but taking images from the area of video where most of actions happen.

    I have attached a screenshot to clarify any doubt about this.

    The Avisynth script for Full HD cases (1080p) is as follow ...
    Code:
    VideoLeft=DirectShowSource("VideoLeft.avi", audio=false)
    VideoLeft=VideoLeft.Crop(480,0,-480,0)
    VideoRight=DirectShowSource("VideoRight.avi")
    VideoRight=VideoRight.Crop(480,0,-480,0)
    StackHorizontal(VideoLeft,VideoRight)
    Turn180()
    FlipHorizontal()
    Subtitle("Video 1 - Left",30,1030,20,3000,"Gaduci",20,$FFFFFF)
    Subtitle("Video 2 - Right",990,1030,20,3000,"Gaduci",20,$FFFFFF)
    NOTE: I don't understand why I have to turn 180º and flip horizontally in Avisynth the resulting comparison but I have to do it.

    If I could do the same using ffmpeg, that could be great, and this solution might be very interesting for many people since such comparisons side by side are helpful for debugging encoding parameters and decisions.

    Thank you very much in advance.
    Mapg
    Image Attached Thumbnails Click image for larger version

Name:	comparison_side_by_side.jpg
Views:	1069
Size:	55.4 KB
ID:	30787  

    Quote Quote  
  2. -vf drawtext can be problematic in ffmpeg, because it relies on font config of individual system, so I left out the text or "labels"

    it's usually better to use variables (like input width, input height), instead of hardcoded numbers like 480, so it's more flexible you can apply to videos of different dimensions

    this example uses ffv1 (lossles) to encode, adjust it as you see fit

    there is no error handling in this example - so if you have incompatibilites like colorspace issues, odd numbers for dimensions etc... it won't work

    Code:
    ffmpeg -i leftvideo.ext -i rightvideo.ext -filter_complex "[0:v] crop=iw/2:ih, pad=2*iw:ih [left]; [1:v] crop=iw/2:ih [right]; [left][right] overlay=main_w/2:0 [out]" -map [out] -c:v ffv1 -an output.avi
    Quote Quote  
  3. Thank you very much!! It's working perfect. It's exactly what I was tring to find.

    Yes you are right, it's much better solution trying to avoid hardcoded the values.

    What I need to do now is to add subtitles to identify videos and adding the sound of one of them.

    I usually compare source and encoded video version so both videos are paired. If you have a quick solution for adding above points is OK, otherwise I will have a look at Saint-Google.

    Thank you again, indeed.

    Best regards,
    Mapg
    Quote Quote  
  4. To add audio, add a second map. e.g -map 0:1 would be 1st file, stream #1 which is usually audio (stream #0 is usually video)

    You can use -c:a copy to copy the audio stream, or -c:a pcm_s16le for uncompressed 16bit PCM wav, or specify some other codec

    You can use a container like MKV to have more compatibility (e.g. if you use uncompressed PCM audio, it won't mux into things like MP4 with open source muxers)

    Code:
    ffmpeg -i leftvideo.ext -i rightvideo.ext -filter_complex "[0:v] crop=iw/2:ih, pad=2*iw:ih [left]; [1:v] crop=iw/2:ih [right]; [left][right] overlay=main_w/2:0 [out]" -map [out] -map 0:1 -c:v ffv1 -c:a copy output.mkv
    Quote Quote  
  5. The -vf drawtext can be problematic in ffmpeg because you have to specify a font file. (In avisynth, the function textsub() is internal , and automatically uses a default font, regardless of system setup). So it's difficult to make it work for everybody automatically. There are ways to get the font config working in ffmpeg automatically but it can be tricky. But one way that works for sure , for everybody, is to specify a location for a "font.ttf" (use whatever font you want) . You have to specify a location, or it has to be in the search path.

    So you would just add "drawtext" to the end of each filter chain. In this example, it says "video1" ,and "video2"

    You can change things like font size, position, color etc, see this for reference of the options
    https://ffmpeg.org/ffmpeg-filters.html#drawtext-1

    eg

    Code:
    ffmpeg -i leftvideo.ext -i rightvideo.ext -filter_complex "[0:v] crop=iw/2:ih, pad=2*iw:ih, drawtext=fontsize=40:fontfile=font.ttf:text="video1" [left]; [1:v] crop=iw/2:ih, drawtext=fontsize=40:fontfile=font.ttf:text="video2" [right]; [left][right] overlay=main_w/2:0 [out]" -map [out] -map 0:1 -c:v ffv1 -c:a copy output.mkv
    Quote Quote  
  6. It worked perfectly!

    I will follow your recommendations.

    Thanks for all.

    Best,
    Mapg
    Quote Quote  



Similar Threads

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