0

I'm using FFMPEG libraries do do some video manipulation, and due to complexity of filters and image overlaying, I have to run the process in multiple passes. This means, my process is as such: Open original video, decode it, run -complex_filter, recompress the video in whichever format the original video was encoded. Open the output from the first pass, run another -complex_filter, etc-etc. Sometimes I have to do the above 3-4 times. My concern is that the video, with every compression is losing quality - obvious signs of that is the file is shrinking in size with every pass.

With the above, I have two questions:

  1. Would it make sense to, after first manipulation, instead of saving the video in its original format, I chose some format that is lossless, and then perform my passes one after the other, knowing that the quality remains the same, then on the final pass I recompress one-time into the format of the source. If so, what format of a video would you recommend? ProRes 4444? Any other formats I shell consider? Any parameters I should set and carry-over from encoding to encoding?

  2. With every step I carry over all extra streams of audio and other meta data. Wouldn't it be more efficient to strip everything except the video, run my video passages over and over and not to need for adding -c:a copy and c:s copy? Then on my final run, merge all streams from the original source to the output file? If yes, how will I carry the ffmpeg command specifically? I have a video that has 1 video stream + 15 audio streams + some extra tmcd which my ffmpeg cannot read.

Thank you.

Edit 1:

if the input video has a video codec = dvvideo, and if dimensions of the video is 1280x1080, that means the video doesn't have a typical square pixels. I first need to resize the video, in doing so I scale the video up. Then I can run my filters:

pass-1: -vf scale=1920x1080 (this step is skipped if the video is of a normal x to y ratio) pass-2: -filter_complex: which calls my special filter that adds some proprietary watermark to a video pass-3: -filter_complex: "0overlay=5:21:enable='between(t,2,3)+between(t,4,5)+between(t,6,8)'" (sole objective is to inserts an icon.png at a location near where the watermark was placed in previous step.) pass-4: -vf scale=1280x1080 (this step scales the video back, if pass-1 was executed)

I could probably rewrite my 'C' filter code at some point in the future to accommodate this logic of checking for 1280x1080, as well as inserting this icon.png, and do it all in one step, but for right now, I thought just using 2-step process if a normal video, or a 4 passes if needs scaling, and utilize something of a lossless format as a temp file solution (I arbitrary chose ProRes 4444 v5, but open to suggestions), should minimize the losses during recompression to the video.

Steps 1 and 4 are conditional, and only applicable if: if vcodec == 'dvvideo' and aspect_ratio < 1.2: # 1280x1080 ratio has about 1.16 I run steps 1->4. Otherwise only steps 2 & 3:

Step1:

ffmpeg -i in.mov -vf scale=1920x1080 -map 0:v? -map 0:a? -map 0:s? -map_metadata 0 -b:v 115084915 -maxrate 115084915 -minrate 115084915 -c:v prores_ks -profile:v 5 -preset ultrafast -crf 0 -c:a copy -timecode 00:00:00.00 -c:s copy -y step2.mov

Step2:

ffmpeg -i step2.mov -filter_complex " myFilter=enable='between(t,0,30)':x=15:y=25:size=95:etc-etc..." -map 0:v? -map 0:a? -map 0:s? -map_metadata 0 -b:v 115084915 -maxrate 115084915 -minrate 115084915 -c:v prores_ks -profile:v 5 -preset ultrafast -crf 0 -c:a copy -timecode 00:00:00.00 -c:s copy -y step3.mov

Step3:

ffmpeg -i step3.mov -i icon.png -filter_complex "[0][1]overlay=15:20:enable='between(t,1,3.600)+between(t,4,5.500)+between(t,6,20)' " -map 0:v? -map 0:a? -map 0:s? -map_metadata 0 -b:v 115084915 -maxrate 115084915 -minrate 115084915 -c:v prores_ks -profile:v 5 -preset ultrafast -crf 0 -c:a copy -timecode 00:00:00.00 -c:s copy -y step4.mov

Step4:

ffmpeg -i step4.mov -map 0:v? -vf scale=1280x1080 -map 0:a? -map 0:s? -c:v dvvideo -pix_fmt yuv422p -b:v 115084915 -maxrate 115084915 -minrate 115084915 -r 29.97 -top 1 -color_primaries bt709 -color_trc bt709 -colorspace bt709 -vtag dvh6 -map_metadata 0 -c:a copy -timecode 00:00:00.00 -c:s copy -y final-output.mov

Since I post my entire set of ffmpeg commands, maybe someone could recommend how to make my output match input so that I don't lose timecode entry:input is on the left panel, my output is on the right

QRrabbit
  • 330
  • 3
  • 14
  • Why can't all filtering be done in one pass? – Gyan Sep 24 '20 at 12:09
  • I don't think I can pipe multiple -complex_filters together. I tried 2 and command has failed, error message was that I can't have more than 1 complex. - The first filter is the most important to me, it applies video manipulation, changing pixels of a video and performs heavy processing. -- my second filter adding a simple icon-overlay, literally pointing an image of a finger to draw viewer's attention to the part where video has been manipulated. --- If there's a way to combine, or at least add imageoverlay without using complex_filter, that would be a winner for me. Please advise. – QRrabbit Sep 24 '20 at 17:24
  • 2
    You should be able to use on instance of `-filter_complex` to perform all of the filtering in one command. Provide all of your commands and we can give you a combined version. – llogan Sep 24 '20 at 17:30
  • @llogan, to illustrate the process: if vcodec = dvvideo, & if the video is 1280x1080, --> video doesn't have square pixels. I resize before runing my filters: pass-1: -vf scale=1920x1080 (this step is skipped if the video is of a normal x to y ratio) pass-2: -filter_complex: which calls my special filter that adds some proprietary watermark to a video pass-3: -filter_complex: "[0][1]overlay=5:21:enable='between(t,2,3)+between(t,4,5)'" (inserts an icon.png at a location near where the watermark was placed in previous step.) pass-4: conditional scale=>1280x1080 (if pass-1 was executed) – QRrabbit Sep 26 '20 at 22:32
  • @llogan, the question is edited, everything after EDIT 1 is new. Thank you for looking into this for me. – QRrabbit Sep 28 '20 at 22:22
  • @llogan, if the encoding can't be combined into fewer steps than 4 in my case, would you at least suggest a file format to use as a temporary holder? I've read somewhere that I could use dev/null, but I don't understand very much how to use it in multiple steps, would you, or anybody else help to explain? Thank you – QRrabbit Oct 01 '20 at 03:51
  • @QRrabbit Posts like this almost never get answered. I could not get motivated to read the wall of text and try to address 8 questions, and try to figure out what you're actually trying to achieve. You are most likely to get answers on this site if you ask 1 concise question per post. So I can only answer your format question: any lossless encoder should do, such as `ffv1` or `-c:v libx264 -crf 0 -preset ultrafast`. – llogan Oct 01 '20 at 17:37

0 Answers0