Page 1 of 1

DVCPRO adds 1 frame to the file metadata

Posted: Thu Aug 15, 2024 6:10 pm
by movalex
I convert SD file to the DVCPRO format with addintional processing. The Source file is 1m0s long, with interlacing and it has audio interleave duration of 1000 ms (25 frames).
When I convert it, the interleave duration becomes 40ms (1 frame), and somehow the host app that airs this file, reports the file is 1 frame longer than 1 minute.
The only way I can solve this is preprocess the file in Resolve, making the duration 1 frame shorter. Then after ffastrans processing, it becomes 1m0s video and 59.965ms audio, which is accepted as correct.
Can I solve this by adjusting the interleave duration of the DVCPRO encoder? Is it possible with FFAStrans?

Here's the ffmpeg command executed by ffastrans:

Code: Select all

-f lavfi -i "aevalsrc=0" -f lavfi -i "color=color=black:size=720x576" -shortest -map_metadata -1 -map 0:0 -filter_complex "[0:1]pan=1|c0=c0,aresample=osr=192000:osf=s32,alimiter=1:1:0.875:0.1:level=0,aresample=ochl=1[a1],[0:1]pan=1|c0=c1,aresample=osr=192000:osf=s32,alimiter=1:1:0.875:0.1:level=0,aresample=ochl=1[a2],[a1][a2]amerge=2,apad[astr1]" -map "[astr1]" -c:a:0 pcm_s16le -ar:a:0 48000 -vf "sidedata=delete,metadata=delete,setrange=tv,crop=w=in_w:h=540:x=0:y=18,colorspace=fast=1:ispace=smpte170m:itrc=smpte170m:iprimaries=bt470bg:all=bt601-6-625,bwdif=mode=1:parity=1,scale=w=720:h=576:flags=lanczos,framerate=50,tinterlace=mode=5,scale=interl=1,format=yuv420p,setfield=bff,setsar=r=1.06666666666667:max=16" -timecode 00:00:00:00 -vtag dvsd -c:v dvvideo -r 25 -top 0 -field_order bb -pix_fmt yuv420p -b:v 25000000 -minrate 25000000 -maxrate 25000000 -color_primaries bt470bg -color_trc smpte170m -colorspace bt470bg -color_range tv -chroma_sample_location topleft -signal_standard 1 -f avi -max_muxing_queue_size 700 -map_metadata -1 -metadata "creation_time=now" -y 
and this is mediainfo of the source:
Format : AVI
Format/Info : Audio Video Interleave
Commercial name : DV
File size : 221 MiB
Duration : 1 min 0 s
Overall bit rate mode : Constant
Overall bit rate : 30.9 Mb/s
Recorded date : 2024-08-12T14:13:26+03:00
Writing application : Adobe Photoshop 23.2 (20220118.orig.521 930aa48) (Windows)

Video
ID : 0
Format : DV
Codec ID : dvsd
Codec ID/Hint : Sony
Duration : 1 min 0 s
Bit rate mode : Constant
Bit rate : 24.4 Mb/s
Width : 720 pixels
Height : 576 pixels
Display aspect ratio : 4:3
Frame rate mode : Constant
Frame rate : 25.000 FPS
Standard : PAL
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Interlaced
Scan order : Bottom Field First
Compression mode : Lossy
Bits/(Pixel*Frame) : 2.357
Time code of first frame : 00:00:00:00 / 00:00:00:00
Time code source : Adobe tc_A / Adobe tc_O
Stream size : 206 MiB (93%)

Audio
ID : 1
Format : PCM
Format settings : Little / Signed
Codec ID : 1
Duration : 1 min 0 s
Bit rate mode : Constant
Bit rate : 1 536 kb/s
Channel(s) : 2 channels
Sampling rate : 48.0 kHz
Bit depth : 16 bits
Stream size : 11.0 MiB (5%)
Alignment : Aligned on interleaves
Interleave, duration : 1000 ms (25.00 video frames)
Interleave, preload duration : 1000 ms
and the info of the wrong length:
Format : AVI
Format/Info : Audio Video Interleave
Commercial name : DV
File size : 217 MiB
Duration : 1 min 0 s
Overall bit rate mode : Constant
Overall bit rate : 30.3 Mb/s
Writing application : Lavf60.17.100

Video
ID : 0
Format : DV
Codec ID : dvsd
Codec ID/Hint : Sony
Duration : 1 min 0 s
Bit rate mode : Constant
Bit rate : 24.4 Mb/s
Width : 720 pixels
Height : 576 pixels
Display aspect ratio : 4:3
Frame rate mode : Constant
Frame rate : 25.000 FPS
Standard : PAL
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Interlaced
Scan order : Bottom Field First
Compression mode : Lossy
Bits/(Pixel*Frame) : 2.357
Time code of first frame : 00:00:00:00
Time code source : ISMP
Stream size : 206 MiB (95%)

Audio
ID : 1
Format : PCM
Format settings : Little / Signed
Codec ID : 1
Duration : 1 min 0 s
Bit rate mode : Constant
Bit rate : 1 536 kb/s
Channel(s) : 2 channels
Sampling rate : 48.0 kHz
Bit depth : 16 bits
Stream size : 11.0 MiB (5%)
Alignment : Aligned on interleaves
Interleave, duration : 40 ms (1.00 video frame)
And this is audio info of the "correct" file:
Audio
ID : 1
Format : PCM
Format settings : Little / Signed
Codec ID : 1
Duration : 59 s 965 ms
Bit rate mode : Constant
Bit rate : 1 536 kb/s
Channel(s) : 2 channels
Sampling rate : 48.0 kHz
Bit depth : 16 bits
Stream size : 11.0 MiB (5%)
Alignment : Aligned on interleaves
Interleave, duration : 40 ms (1.00 video frame)

Re: DVCPRO adds 1 frame to the file metadata

Posted: Sat Aug 17, 2024 8:05 am
by FranceBB
Hi movalex,
I think this is a side effect of one very important check that the filter_builder makes. Effectively, the filter_builder checks that the audio and video are exactly of the same length and if they're not it pads them. In this case, the padding makes it result as 1 frame longer. I know that in Mediainfo you're seeing both being at 1 minute but it might be worth using the detailed view to see exactly how long they last. Even then, it might be just the container lying. What I generally do in this case is to index the file in Avisynth with LWLibavVideoSource() and LWLibavAudioSource() and then check them in avspmod mod. Anyway, if your source is consistent and you always get 1 added frame consistently and you see it "fixed" when you get rid of one frame, then you can technically do one thing: trim it.

Effectively what I'm thinking about is:

Watch -> A/V Decoder (Indexing) -> Custom AVS Script (trim) -> DVCPRO Encoder.

Make sure to set the A/V Decoder to "no decode" and "same as source" for both audio and video. Oh and untick the force 8bit thingie.

In the Custom AVS Script you can do something like:

Code: Select all

my_last_frame=m_clip.FrameCount()-1
m_clip=Trim(m_clip, 0, my_last_frame)

return m_clip
This will remove one frame, thus hopefully reproducing what you were doing in Adobe Premiere.
Please make sure to untick the "clear media properties" tickbox in the Custom AVS Script.


Let me know how it goes and keep in mind that unfortunately I don't have my PC in front of me this very moment so I can't test the script but I will on Monday.

Re: DVCPRO adds 1 frame to the file metadata

Posted: Sun Aug 18, 2024 12:37 am
by movalex
Thanks, will check that!
Also how exactly do you check the length with avspmod? My intention is to check if the length is not longer or shorter than a whole amount of minutes, like 1, 2 or 3.

Re: DVCPRO adds 1 frame to the file metadata

Posted: Tue Aug 20, 2024 5:38 pm
by FranceBB
movalex wrote: Sun Aug 18, 2024 12:37 am Thanks, will check that!
Let me know how it goes. :)
In the meantime I did check it with an actual file and it worked. :D
movalex wrote: Sun Aug 18, 2024 12:37 am Also how exactly do you check the length with avspmod?
Oh, that's pretty easy, the first thing I've done was indexing a file with LWLibav and after that I checked at the bottom left how many frames it counted:

Code: Select all

video=LWLibavvideoSource("\\mibctvan000\Ingest\MEDIA\temp\Emotion_UK\M9101400_03.mxf")
audio=LWLibavAudioSource("\\mibctvan000\Ingest\MEDIA\temp\Emotion_UK\M9101400_03.mxf", stream_index=1)
AudioDub(video, audio)
Screenshot from 2024-08-20 18-32-30.png
Screenshot from 2024-08-20 18-32-30.png (1.39 KiB) Viewed 4303 times
Then I added the code I posted before, but without the m_clip 'cause that's something you only need in FFAStrans:

Code: Select all

video=LWLibavvideoSource("\\mibctvan000\Ingest\MEDIA\temp\Emotion_UK\M9101400_03.mxf")
audio=LWLibavAudioSource("\\mibctvan000\Ingest\MEDIA\temp\Emotion_UK\M9101400_03.mxf", stream_index=1)
AudioDub(video, audio)


my_last_frame=FrameCount()-1
Trim(0, my_last_frame)
and sure enough it was one frame less:
Screenshot from 2024-08-20 18-35-31.png
Screenshot from 2024-08-20 18-35-31.png (1.27 KiB) Viewed 4303 times

And you can of course increase the value to get rid of more frames like -2 -3 -4 -5 etc.
In FFAStrans it would be:

Code: Select all

my_last_frame=m_clip.FrameCount()-1
m_clip=Trim(m_clip, 0, my_last_frame)

return m_clip
but you can also try with:

Code: Select all

my_last_frame=m_clip.FrameCount()-2
m_clip=Trim(m_clip, 0, my_last_frame)

return m_clip
and so on by increasing the frame count until you get the sweet spot.
Now, if you had to measure and make sure that the clips are all of a very specific length, like, let's say, all 1 minute long or all 2 minutes long etc, then it's gonna be slightly more complicated as you need to know the input framerate and then add a bunch of conditionals to check the length and convert the timecode into frames so that you're gonna know how many frames need to be trimmed.
Anyway, for now let's just stick to the simple solution of trimming one frame out from the end and let's see where we go from there. :)

Re: DVCPRO adds 1 frame to the file metadata

Posted: Wed Sep 18, 2024 11:23 pm
by movalex
Thank you @FranceBB, the Avisynth frame clipping command works as you described.
However, just to be sure, I downgraded my FFASTrans deploy from 1.4.0 to the previous version 1.3.1, and with the same workflow and the same file I got the correct output.
I believe this is something that was introduced in the 1.4.0 that adds additional data to the DVCPRO encoder.
Here's some details:

1min file (SD 720x576) converted to DVCPRO with 1.4.0 produces 1m 0s file with the file length of 222410 Kb (incorrect file length, 1 frame extra)

Code: Select all

VIDEO:
Duration                                 : 60040
Duration                                 : 1 min 0 s
Duration                                 : 1 min 0 s 40 ms
Duration                                 : 1 min 0 s
Duration                                 : 00:01:00.040
Duration                                 : 00:01:00:01
Duration                                 : 00:01:00.040 (00:01:00:01)

AUDIO:
Duration                                 : 60005
Duration                                 : 1 min 0 s
Duration                                 : 1 min 0 s 5 ms
Duration                                 : 1 min 0 s
Duration                                 : 00:01:00.005
Duration                                 : 00:01:00.005

File size                                : 227603090
1min file converted to DVCPRO with 1.3.1 produces 1m 0s file with the file length of 222269 Kb (correct file length)

Code: Select all

VIDEO:
Duration                                 : 60000
Duration                                 : 1 min 0 s
Duration                                 : 1 min 0 s 0 ms
Duration                                 : 1 min 0 s
Duration                                 : 00:01:00.000
Duration                                 : 00:01:00:00
Duration                                 : 00:01:00.000 (00:01:00:00)

AUDIO:
Duration                                 : 60005
Duration                                 : 1 min 0 s
Duration                                 : 1 min 0 s 5 ms
Duration                                 : 1 min 0 s
Duration                                 : 00:01:00.005
Duration                                 : 00:01:00:00
Duration                                 : 00:01:00.005 (00:01:00:00)

File size                                : 227747114
Note that the duration of the audio in the second file is still 5ms longer than the source, but that seems acceptable.
I will include the workflow too. Hopefully @emcodem would be able to check that too.

UPD: I also tried to convert HD to SD DV with the same workflow, but again got the wrong length, this time in v1.3.1 too. This time the audio track becomes 91ms longer than the one in the the source file, and the video track is 40 ms longer.

Code: Select all

VIDEO:
Duration                                 : 60040
Duration                                 : 1 min 0 s
Duration                                 : 1 min 0 s 40 ms
Duration                                 : 1 min 0 s
Duration                                 : 00:01:00.040
Duration                                 : 00:01:00:01
Duration                                 : 00:01:00.040 (00:01:00:01)

AUDIO:
Duration                                 : 60091
Duration                                 : 1 min 0 s
Duration                                 : 1 min 0 s 91 ms
Duration                                 : 1 min 0 s
Duration                                 : 00:01:00.091
Duration                                 : 00:01:00.091

File size                                : 227619474
This all seem pretty random to me. Hopefully you have an idea what is happening here.

UPD2: Is it possible thats an ffmpeg version bug? I'm not sure how to check for that, dvcpro encoder command seems pretty complicated to reproduce. Is there a better way to encode dvvideo without any duration issues?

Re: DVCPRO adds 1 frame to the file metadata

Posted: Thu Sep 19, 2024 8:02 pm
by emcodem
Hi,

i guess it depends on ffmpeg version. As far as i can see, it is caused by the filter "apad" which is inserted automatically into the ffmpeg filter chain by ffastrans and according to my tests, the amount of unneccessary added audio depends a little on ffmpeg version/build.
Basically it is not "acceptable" to see 5 ms audio too much in the output when input and output is PCM audio, such stuff should only happen with e.g. aac that does not have a frame size that matches the video.

A number of possible workarounds comes to my head, one is to use the s_options feature but this is only supported from 1.4 onwards.

So, what we want to do? We want to "alter" the ffastrans internally calculated encoding command and just remove the "apad" filter.
How to do this using s_options:

1) before the encoder processor, insert a populate proc and set builtin variable s_options to : skip_encoding=True|save_enc_cmd=True
2) this really "disables" the encoding, so the encoding processor will just calculate the ffmpeg command and populate it to the inbuilt variable "%s_last_enc_cmd%"
3) from here all we need to do is to replace ",apad" from s_last_enc_cmd and after that just use a cmd processor to execute the calculated command line
4) no need to think about s_source or anything else, everything works just as if the encoding processor would have encoded normally


After these 3 steps, the audio had exactly the same duration as video for me but i noticed that exactly 2 frames were missing in the output. As i see this is done "intentionally" by the "Fade" processor. To disable this behaviour, we need to check "Add black frames" in the Fade processor.

Try this. Changes are exactly as mentioned above, including the Add black frames checkbox in Fade proc.
NAEFIR SD DV_emcodem.json
(19.96 KiB) Downloaded 2 times