#1  
07-30-2021, 02:25 AM
kingbean kingbean is offline
Free Member
 
Join Date: Jun 2020
Location: Australia
Posts: 46
Thanked 1 Time in 1 Post
Hello,

I am capturing my VHS tapes to lossless HuffYUV AVI files.

For uploading to YouTube/sharing, I am using ffmpeg to change the storage aspect ratio and re-encode to H.264 MKV files. This is working fine and I've got no problems.

For archiving the original HuffYUV files, I am using ffmpeg to change the display aspect ratio and remux into an MKV. I am changing the DAR only, with the intention being simple playback at the correct aspect ratio with no other changes to the file. SAR is not changed and the file is not re-encoded.

This was going fine working with my PAL tapes (I think), but now I've tried NTSC and I'm having difficulties. I've done a lot of Googling over the past few hours but haven't really got a clear answer.

My captured files (HuffYUV AVI):

PAL: 720x576 (5:4)
NTSC: 720x480 (3:2)

My ffmpeg command:

ffmpeg.exe -i input.avi -aspect 4:3 -c:a copy -c:v copy output.mkv

My proposed archive files (HuffYUV MKV):

PAL: 768x576 (4:3)
NTSC: 720x540 (4:3)

Now, most of what I'm reading online (and everything I knew about NTSC prior to this - mostly working at DVD level) was that the NTSC 4:3 resolution should be 640x480. So, I guess that leaves me with a few questions:

1. For the purposes of direct file playback only (no streaming or disc authoring), is there any downside to having a 720x540 4:3 DAR as opposed to 640x480?

2. If preferable, is there a way to flag the MKV to opt for 640x480 instead, while keeping the video stream otherwise unaltered? Preferably from the ffmpeg cmd line.

3. Is my PAL output correct? I think it's good, but now I'm so confused about NTSC I'm not certain.

As a final note: I am not looking to do any cropping/masking, I only want to store the raw capture file in an MKV container with DAR flags to correct the aspect ratio. As such, I haven't given any thought to cropping/masking the borders/'overscan' areas, 704x480 resolutions, etc. Is this part of my problem?

Thanks in advance!
Reply With Quote
Someday, 12:01 PM
admin's Avatar
Ads / Sponsors
 
Join Date: ∞
Posts: 42
Thanks: ∞
Thanked 42 Times in 42 Posts
  #2  
07-30-2021, 02:45 AM
lollo2 lollo2 is offline
Free Member
 
Join Date: Mar 2013
Location: Italy
Posts: 673
Thanked 189 Times in 163 Posts
For a PAL 720x576 capture SAR (Storage Aspect Ratio)=720/576, DAR (Display Aspect Ratio)=4/3 and PAR (Pixel Aspect Ratio)=DAR/SAR=16/15

Avi HuffyYUV files have no DAR information, with ffmpeg you can add the DAR parameter to the file, without changing anything else (you can also keep the same avi container)

Code:
ffmpeg.exe -i input.avi -aspect 4:3 -c copy output.avi
In this way, any player reading the DAR for displaying the video, will stretch it to proper 768x576 (576xDAR=576x4/3=768); ffmpeg documentation generally calls "SAR" what normally is called "DAR", generating some confusion.

For NTSC (where I have no experience) it should be the same with its own numbers, 720x480, but it is better if you wait the answer from some experienced NTSC user.

Last edited by lollo2; 07-30-2021 at 02:56 AM.
Reply With Quote
The following users thank lollo2 for this useful post: kingbean (07-30-2021)
  #3  
07-30-2021, 03:03 AM
kingbean kingbean is offline
Free Member
 
Join Date: Jun 2020
Location: Australia
Posts: 46
Thanked 1 Time in 1 Post
Yeah it definitely gets confusing. I didn't realise the SAR/DAR terminology in ffmpeg documentation - but that shouldn't be an issue given the command is "aspect"?

Running the -aspect 4:3 command, it gives me the following:

Code:
Stream #0:0: Video: huffyuv (HFYU / 0x55594648), yuv422p, 720x480 [SAR 8:9 DAR 4:3], q=2-31, 65397 kb/s, 29.97 fps, 29.97 tbr, 1k tbn
In this case, SAR and DAR are the correct way around, right?
Reply With Quote
  #4  
07-30-2021, 03:31 AM
lollo2 lollo2 is offline
Free Member
 
Join Date: Mar 2013
Location: Italy
Posts: 673
Thanked 189 Times in 163 Posts
I think so. Play with VLC and in Video -> Aspect Ratio change from Default (=DAR) to 4:3. Nothing should change. (If you do the same with the original file vithout the DAR flag the proportions change)

Edit: what ffmpeg calls SAR in its output is what normally is called PAR :-(
Reply With Quote
  #5  
07-30-2021, 03:37 AM
kingbean kingbean is offline
Free Member
 
Join Date: Jun 2020
Location: Australia
Posts: 46
Thanked 1 Time in 1 Post
Yep all good there. The files are displaying and playing back correctly, the 4:3 ratio is no problem - my concern more so is: is the 720x540 resolution a problem?

Sounds like, form what you've said, my PAL outputs are fine, so it's just a matter of the NTSC.
Reply With Quote
  #6  
07-30-2021, 03:56 AM
lollo2 lollo2 is offline
Free Member
 
Join Date: Mar 2013
Location: Italy
Posts: 673
Thanked 189 Times in 163 Posts
Not sure I understand what is 720x540. If a PAL capture is 720x576, should not a NTSC capture be 720x480? Then the same formulas should apply replacing 576 with 480. Some NTSC experienced user will surely help you.

Last edited by lollo2; 07-30-2021 at 04:19 AM.
Reply With Quote
  #7  
07-30-2021, 01:06 PM
latreche34 latreche34 is offline
Free Member
 
Join Date: Dec 2015
Location: USA
Posts: 3,257
Thanked 537 Times in 497 Posts
I don't think you are heading the right way, Avoid resizing as much as you can, Don't crop vertically and only crop to 704 horizontally to remove the black pillars added by the capture card:

http://www.digitalfaq.com/forum/vide...html#post74958
Reply With Quote
  #8  
07-30-2021, 06:36 PM
kingbean kingbean is offline
Free Member
 
Join Date: Jun 2020
Location: Australia
Posts: 46
Thanked 1 Time in 1 Post
Thanks for replying. I have that thread bookmarked and have re-read your post multiple times trying to wrap my head around this.

Quote:
Originally Posted by latreche34 View Post
Here are some SAR values for the 4:3 frame:

NTSC:
720x480 (DV/DVD, Full frame) -> SAR=8/9
704x480 (Analog Capture, SD Crop) -> SAR=10/11
640x480 (Square pixel, SD Resize) -> SAR=1

PAL/SECAM:
720x576 (DV/DVD, Full frame) -> SAR=16/15
704x576 (Analog Capture, SD Crop) -> SAR=12/11
768x576 (Square pixel, SD Resize) -> SAR=1
From what I understand, there is no difference to changing DAR rather than SAR, other than DAR sets flags and SAR will process the video. Correct?

Since I am looking to avoid any processing of the video stream, are you saying I need to set MKV crop flags, and then set DAR?

Maybe I should clarify my entire workflow, I might be more confused that I thought I was...

HuffYUV AVI to H.264 MKV: (for YouTube/sharing)

My .AVS file:

Code:
SetMTMode(5, 11)
AVISource("input.avi")
SetMTMode(2)
AssumeTFF()
ConvertToYV12(interlaced=true)
QTGMC(preset="faster", EdiThreads=6, ChromaMotion=true, border=false)
Which feeds into a .bat file:

Code:
:: encode video with x264\x264-8bit
:: --sar=12:11 for PAL --sar=10:11 for NTSC
x264-8bit.exe --preset=medium --sar=12:11 --crf=14 --output "outvid.264" "%~1"

:: take audio from input file and extract to flac
ffmpeg.exe -y -i "%~1" -vn -acodec flac "outaud.flac"

:: repack .264 and .flac files into MKV container with original file name
mkvmerge.exe -o "H:\%~n1.mkv" "outvid.264" "outaud.flac"
I've yet to run any NTSC files through that, however on checking my PAL output I see now that the output is 785x576 Cropping the borders would solve this? Something like:

Code:
SetMTMode(5, 11)
AVISource("input.avi")
SetMTMode(2)
AssumeTFF()
ConvertToYV12(interlaced=true)
QTGMC(preset="faster", EdiThreads=6, ChromaMotion=true, border=false)
Crop(8, 0, 704, 576)
Substituting 576 with 480 for NTSC.

Running the files through that, using sar=12:11 for PAL and sar=10:11 for NTSC, I get the following message during the final muxing:

PAL:
Code:
'outvid.264' track 0: Extracted the aspect ratio information from the MPEG-4 layer 10 (AVC) video data and set the display dimensions to 768/576.
Resulting file is 704x576 with aspect ratio reported as 4:3 (1.33), giving 768x576 playback - however this is not suitable for YouTube, as square pixels are required? Should I have a resize filter in my AviSynth script as well, something like Spline36Resize(768,576)?

NTSC:
Code:
'outvid.264' track 0: Extracted the aspect ratio information from the MPEG-4 layer 10 (AVC) video data and set the display dimensions to 704/528.
Resulting file is 704x480 file with aspect ratio reported as 4:3 (1.33), giving 704x528 playback. Am I cropping incorrectly?

Sorry, I'm feeling rather lost now. Any pointers or sample scripts would be greatly appreciated!

HuffYUV AVI to HuffYUV MKV: (for archiving and direct file playback)

No .AVS file.

ffmpeg remux:

Code:
ffmpeg.exe -i input.avi -aspect 4:3 -c:a copy -c:v copy output.mkv
Putting a PAL video through that gives me a 720x576 file. Aspect ratio reported as 4:3 (1.33), giving 768x576 playback - perfect for what I want here. If there's a way to crop borders without video processing or compromising playback support, I'm all ears, but otherwise, no further concerns for PAL archiving.

Putting an NTSC video through that gives me a 720x480 file. Aspect ratio reported as 4:3 (1.33), giving 720x540 playback - is there any reason I should be forcing this to play back as 640x480 instead, and if so how?
Reply With Quote
  #9  
07-30-2021, 11:19 PM
latreche34 latreche34 is offline
Free Member
 
Join Date: Dec 2015
Location: USA
Posts: 3,257
Thanked 537 Times in 497 Posts
You either set the pixel aspect ratio SAR or display aspect ratio DAR, don't do both or it will resize your output, I myself just set the SAR based on 704 to avoid 3% stretch. Note that the analog aspect ratio is based on 704 not 720 because 720 is for digital formats such as DV and DVD. I'm not too sure if setting the SAR will process the video, I've never done it without encoding anyway so I wouldn't know.

For youtube resize from 704x480(576) to 1440x1080 for square pixel, as a bonus youtube sees your video as HD and applies less compression.
Reply With Quote
  #10  
07-31-2021, 04:37 AM
kingbean kingbean is offline
Free Member
 
Join Date: Jun 2020
Location: Australia
Posts: 46
Thanked 1 Time in 1 Post
Can you provide a sample script/cmd of how you do that? All I have seen for ffmpeg is -aspect 4:3 which sets the DAR. And gives me 720x540 instead of 640x480.

Regarding YouTube, would Spline36Resize(1440,1080) after cropping be best? Or should I be resizing in ffmpeg/x264. I thought upscaling was a no-no. Does that change between NTSC and PAL? I haven't got time to test just now but will have a play with it tomorrow.

Thanks again.
Reply With Quote
  #11  
07-31-2021, 10:47 AM
latreche34 latreche34 is offline
Free Member
 
Join Date: Dec 2015
Location: USA
Posts: 3,257
Thanked 537 Times in 497 Posts
Resizing is for youtube only, Always keep a master copy of the original 704x480 4:2:2 lossless files.
I personally use AvsPmod, I drop the cropping, de-interlacing and resizing scripts there and process them all at once for youtube, it uses vdub plugin and QTGMC and gives you a visual frame to see the effect of each script instantly. I never encode for youtube, I just gives it the resulting lossless HuffYUV files after de-interlacing and resizing to 1440x1080 and let it use its own encoding, That's how you get the best quality for youtube.

I will post a copy of some scripts when I get home.
Reply With Quote
  #12  
07-31-2021, 05:12 PM
kingbean kingbean is offline
Free Member
 
Join Date: Jun 2020
Location: Australia
Posts: 46
Thanked 1 Time in 1 Post
Thanks!

As I mentioned, I'm keeping the master lossless files, simply looking to remux into MKV with appropriate aspect ratio.

Quote:
Originally Posted by latreche34 View Post
Always keep a master copy of the original 704x480 4:2:2 lossless files.
Are you capturing at this resolution?? Or are you going:

- Capture file: Lossless 720x480
- Cropped file: Lossless 704x480
- Delete capture file
- Cropped file is now the master copy?
- Run all processing using new cropped master copy

All I want is:

- Original HuffYUV AVI repacked in MKV with aspect flags (I'm happy with no cropping for these)
- Deinterlaced, cropped and resized H264 for YouTube (you are suggesting not using H264?)

My problem is:
- Setting DAR 4:3 on NTSC AVI gives me 720x540, not 640x480
- Completely lost on best method for YouTube

Would love to see some scripts, thanks!
Reply With Quote
  #13  
07-31-2021, 05:26 PM
latreche34 latreche34 is offline
Free Member
 
Join Date: Dec 2015
Location: USA
Posts: 3,257
Thanked 537 Times in 497 Posts
Capturing at 720 and cropping to 704, Again it's only about 3% stretch if you keep 720 and don't mind the ugly 16 grey pixels on the sides of the frame. 704 is accurate, 720 is an approximation according to the D1 standard.

Encoding for playback I use these ffmpeg scripts depends on whether the video is de-interlaced or kept interlaced:

Code:
NTSC i:
ffmpeg -i In.avi -vf "scale=w=-1:h=-1:interl=1,format=yuv420p,setsar=sar=10/11" -flags +ildct+ilme -c:v libx264 -crf 18 -x264opts bff=1:colorprim=smpte170m:transfer=smpte170m:colormatrix=smpte170m:force-cfr -c:a aac -b:a 192k Out.mp4

NTSC p:
ffmpeg -i In.avi -vf "format=yuv420p,setsar=sar=10/11" -c:v libx264 -crf 10 -x264opts colorprim=smpte170m:transfer=smpte170m:colormatrix=smpte170m:force-cfr -c:a aac -b:a 192k Out.mp4

PAL i :
ffmpeg -i In.avi -vf "scale=w=-1:h=-1:interl=1,format=yuv420p,setsar=sar=12/11" -flags +ildct+ilme -c:v libx264 -crf 10 -x264opts bff=1:colorprim=smpte170m:transfer=bt470bg:colormatrix=bt470bg:force-cfr -c:a aac -b:a 192k Out.mp4

PAL p:
ffmpeg -i in.avi -vf "format=yuv420p,setsar=sar=12/11" -c:v libx264 -crf 10 -x264opts colorprim=smpte170m:transfer=bt470bg:colormatrix=bt470bg:force-cfr -c:a aac -b:a 192k Out.mp4
Reply With Quote
  #14  
07-31-2021, 06:55 PM
traal traal is offline
Free Member
 
Join Date: Jan 2016
Posts: 393
Thanked 74 Times in 67 Posts
Quote:
Originally Posted by kingbean View Post
1. For the purposes of direct file playback only (no streaming or disc authoring), is there any downside to having a 720x540 4:3 DAR as opposed to 640x480?
With a 720x480 SAR file, 720x540 and 640x480 PAR are exactly the same thing. "720x540" just tells you that your video player window needs to be at least that big to see all the pixels.

A slightly different question is, which is a better resolution for capture, 720x480 or 640x480? I like 720x480 because it matches DVD, but others like 640x480 because of the square pixels, and both are high enough capture resolutions for VHS so there's no right answer.
Reply With Quote
The following users thank traal for this useful post: kingbean (07-31-2021)
  #15  
07-31-2021, 08:03 PM
latreche34 latreche34 is offline
Free Member
 
Join Date: Dec 2015
Location: USA
Posts: 3,257
Thanked 537 Times in 497 Posts
Capturing is always 720, Some capture cards have the option to resize on the fly but there is no such 640 capturing.
Reply With Quote
  #16  
07-31-2021, 09:31 PM
lordsmurf's Avatar
lordsmurf lordsmurf is offline
Site Staff | Video
 
Join Date: Dec 2002
Posts: 13,501
Thanked 2,447 Times in 2,079 Posts
Quote:
Originally Posted by latreche34 View Post
Capturing is always 720, Some capture cards have the option to resize on the fly but there is no such 640 capturing.
That's not accurate.

Some cards do have 640x480 hardware limitation, but it's mostly ancient late 90s capture hardware, or cheap Chinese 2000s cards (USB, PCI, other). I know of several USB1 cards that did 640x480, but I forget the names now, that was literally decades ago.

So while not accurate, nothing you'd see today. None of that stuff will run on modern Win7/8/10, and in fact many quite working due to Windows XP, being 95/98/98SE/ME hardware only.

In 2021, this is trivia, a footnote.

- Did my advice help you? Then become a Premium Member and support this site.
- For sale in the marketplace: TBCs, workflows, capture cards, VCRs
Reply With Quote
  #17  
07-31-2021, 09:47 PM
kingbean kingbean is offline
Free Member
 
Join Date: Jun 2020
Location: Australia
Posts: 46
Thanked 1 Time in 1 Post
Quote:
Originally Posted by traal View Post
With a 720x480 SAR file, 720x540 and 640x480 PAR are exactly the same thing. "720x540" just tells you that your video player window needs to be at least that big to see all the pixels.
Great, thank you, that settles that part of my dilemma, then. I'll continue to set DAR 4:3 and archive the 720x576/768x576 and 720x480/720x540 master files.

I've got no intention to change my capture resolutions, 720 is perfect.

Quote:
Originally Posted by latreche34 View Post
Code:
NTSC i:
ffmpeg -i In.avi -vf "scale=w=-1:h=-1:interl=1,format=yuv420p,setsar=sar=10/11" -flags +ildct+ilme -c:v libx264 -crf 18 -x264opts bff=1:colorprim=smpte170m:transfer=smpte170m:colormatrix=smpte170m:force-cfr -c:a aac -b:a 192k Out.mp4

PAL i :
ffmpeg -i In.avi -vf "scale=w=-1:h=-1:interl=1,format=yuv420p,setsar=sar=12/11" -flags +ildct+ilme -c:v libx264 -crf 10 -x264opts bff=1:colorprim=smpte170m:transfer=bt470bg:colormatrix=bt470bg:force-cfr -c:a aac -b:a 192k Out.mp4
I'll try out these ffmpeg scripts now and see how I go with them.
Reply With Quote
  #18  
07-31-2021, 10:41 PM
traal traal is offline
Free Member
 
Join Date: Jan 2016
Posts: 393
Thanked 74 Times in 67 Posts
So, I prefer to archive the original .avi files verbatim as they came from the capture card (or rather VirtualDub), in case any software I use post-capture unexpectedly changes something in the file and I don't realize until it's too late.

Instead, I set the DAR in MkvToolNix when I'm combining the separately restored audio and video streams and creating chapters. (I don't know of an easier way to create chapters.)
Reply With Quote
  #19  
07-31-2021, 10:43 PM
kingbean kingbean is offline
Free Member
 
Join Date: Jun 2020
Location: Australia
Posts: 46
Thanked 1 Time in 1 Post
Quote:
Originally Posted by latreche34 View Post
Encoding for playback I use these ffmpeg scripts depends on whether the video is de-interlaced or kept interlaced:[/CODE]
Sorry I think I may have confused you with my rambling questions.

For playback I do not want ANY encoding whatsoever. Just a simple DAR change. traal's post above has put my mind at ease on this matter.

The only encoding I want to do is from the raw capture file to a YouTube friendly mkv/mp4. I tried the ffmpeg scripts you provided, but it didn't seem to be what I'm after. My interlaced, 720x480 NTSC AVI became an interlaced, 720x480/720x528 1.36 ratio MP4.

You'd mentioned earlier about giving YouTube a 1440x1080 file? Can you break it down step by step?

HuffYUV AVI > AviSynth script > ffmpeg script > YouTube friendly file

Scripts should be something like...

Code:
SetMTMode(5, 11)
AVISource("input.avi")
SetMTMode(2)
AssumeTFF()
ConvertToYV12(interlaced=true)
QTGMC(preset="faster", EdiThreads=6, ChromaMotion=true, border=false)
Crop(8, 0, 704, 576)
Spline36Resize(1440,1080)
and then

Code:
ffmpeg -i "%~1" -c:v libx264 -crf 14 -x264opts bff=1:colorprim=smpte170m:transfer=smpte170m:colormatrix=smpte170m:force-cfr -c:a aac -b:a 192k Out.mp4
Something like that??

Not sure what the red parts in the x264 options do exactly - I noticed your transfer and colormatrix settings differed between NTSC and PAL.

NTSC: transfer=smpte170m:colormatrix=smpte170m
PAL: transfer=bt470bg:colormatrix=bt470bg

Quote:
Originally Posted by traal View Post
So, I prefer to archive the original .avi files verbatim as they came from the capture card (or rather VirtualDub) ...

Instead, I set the DAR in MkvToolNix when I'm combining the separately restored audio and video streams and creating chapters.
My goal here is to archive the AVIs un-restored, for now. I'm working through a collection of 1800+ tapes, each averaging between 4-7 separate concerts per tape.. so, the thought of even attempting restoration as part of my process makes me weak at the knees.

Re-packing into MKV with a DAR is to allow them to play back at the correct ratio, with no other changes. Then, down the track, restoration is still possible, when time/desire permits.

Are there any risks with remuxing AVI > MKV? Would I be better off just leaving them along and manually adjusting aspect during playback?

In the meantime, a deinterlaced H264 file goes onto YouTube and is then deleted from my system.
Reply With Quote
  #20  
08-01-2021, 12:06 AM
traal traal is offline
Free Member
 
Join Date: Jan 2016
Posts: 393
Thanked 74 Times in 67 Posts
Quote:
Originally Posted by kingbean View Post
Are there any risks with remuxing AVI > MKV?
The risk is very low, I admit.

Oh, I would add
Code:
-tune grain
to your ffmpeg line so it doesn't replace VHS "grain" with macroblocking.
Reply With Quote
Reply




Similar Threads
Thread Thread Starter Forum Replies Last Post
Why is VHS stored aspect ratio different from DAR? Duxa General Discussion 5 02-04-2023 08:41 AM
Aspect Ratio problem with NTSC tapes? latreche34 Videography: Cameras, TVs and Players 15 05-28-2018 03:30 AM
Understanding PAL aspect ratio? spanak Encode, Convert for discs 4 04-17-2018 02:16 AM
Need help fixing aspect ratio wayshway Videography: Cameras, TVs and Players 8 04-30-2008 04:10 PM
Help Fix Aspect Ratio Konfusion Restore, Filter, Improve Quality 3 11-04-2006 01:43 PM

Thread Tools



 
All times are GMT -5. The time now is 04:15 AM