#5092 closed defect (fixed)
Field order wrong for DV HD
Reported by: | Dan | Owned by: | |
---|---|---|---|
Priority: | normal | Component: | avcodec |
Version: | git-master | Keywords: | dvvideo |
Cc: | Michael Niedermayer, Aleksandr | Blocked By: | |
Blocking: | Reproduced by developer: | no | |
Analyzed by developer: | no |
Description
The field order (i.e. topfield first) is wrong for DV HD video. It's actually due to a stupid change they made to the spec. The bits in the VAUX are the same but their meaning changed. In SMPTE 314M, which is for SD, field 2 refers to the even fields and field 1 refers the odd fields. But in SMPTE 370M, which is for HD, field 1 refers to the even fields and field 2 refers to the odd fields. So if the FS bit in the VAUX is 1 it means BFF in SD but TFF in HD.
So we need a line in the code to flip the TFF flag if the file is HD. (the current code parses it according to the SMPTE 314M spec regardless of resolution)
Attachments (3)
Change History (23)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
Priority: | important → normal |
---|
Please either:
- Send a patch made with
git format-patch
to the FFmpeg development mailing list that fixes the issue you see.
or
- Provide both a sample that allows to reproduce the issue you want to report and the command line that allows to reproduce the issue and the complete, uncut console output of current FFmpeg git head to make this a valid ticket.
comment:3 by , 9 years ago
I don't know how to create a patch.
I have sample files that demonstrate the issue but they are big. About 1GB each so I'm not sure where I could put them for you.
comment:6 by , 9 years ago
The suggested change does not compile
"libavcodec/dvdec.c:552:13: error: assignment of member ‘top_field_first’ in read-only object"
I think the change is based on a old version of FFmpeg
Also can you quote the 2 specs where the interpretation of the bit differs ?
(this will make it easier to verify that the change is correct)
comment:7 by , 9 years ago
Cc: | added |
---|
comment:8 by , 8 years ago
Example DVCProHD file, recorded as TFF, and shown in some popular players (Edius, Adobe Premiere, Final Cut) as TFF, but decoded with ffmpeg as BFF:
AVFrame->interlaced_frame = 1 AVFrame->top_field_first = 0
follow-up: 11 comment:9 by , 8 years ago
Cc: | added |
---|---|
Component: | undetermined → avcodec |
Keywords: | dvvideo added |
Version: | unspecified → git-master |
How did you test this?
I ask because FFmpeg correctly shows tff here on the console and correctly uses tff when using a deinterlacer (tested with yadif).
by , 8 years ago
Attachment: | sop_DVCProHD_cut.mov added |
---|
follow-up: 13 comment:10 by , 8 years ago
I attached a sample for testing sop_DVCProHD_test.mov.
Can you test if popular players (Edius, Adobe Premiere, Final Cut) interpret this file as TFF or BFF?
by , 8 years ago
Attachment: | sop_DVCProHD_test2.mov added |
---|
Original cut sample with fiel atom replaced by free atom
comment:11 by , 8 years ago
Replying to cehoyos:
How did you test this?
I ask because FFmpeg correctly shows tff here on the console and correctly uses tff when using a deinterlacer (tested with yadif).
By watching
AVFrame->interlaced_frame
and
AVFrame->top_field_first
in the debugger, and watching how they're filling in libavcodec/dvdec.c :
/* Determine the codec's sample_aspect ratio from the packet */ vsc_pack = buf + 80 * 5 + 48 + 5; if (*vsc_pack == dv_video_control) { apt = buf[4] & 0x07; is16_9 = (vsc_pack[2] & 0x07) == 0x02 || (!apt && (vsc_pack[2] & 0x07) == 0x07); ff_set_sar(avctx, s->sys->sar[is16_9]); } if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) return ret; frame->interlaced_frame = 1; frame->top_field_first = 0; /* Determine the codec's field order from the packet */ if ( *vsc_pack == dv_video_control ) { frame->top_field_first = !(vsc_pack[3] & 0x40); }
The situation is strange, because SMPTE 370m and 314m tells about bit (vsc_pack[3] & 0x40), that:
FS: First/second field flag FS indicates a field which is delivered during the field one period. 0 = Field 2 is delivered; 1 = Field 1 is delivered. FF FS Output field 1 1 Field 1 and field 2 are output in this order (1,2 sequence) 1 0 Field 2 and field 1 are output in this order (2,1 sequence) 0 1 Field 1 is output twice 0 0 Field 2 is output twice
same for both 1080 system and 720 system.
This is actually not what ffmpeg does:
frame->top_field_first = !(vsc_pack[3] & 0x40);
but this code works correctly for dv sd files.
comment:12 by , 8 years ago
for 720 system it tells:
For the 720-line system (see table 17) FS indicates a video frame which is delivered during the video frame one period. 0 = Video frame 2 is delivered. 1 = Video frame 1 is delivered. Table 17 – FF/FS for the 720-line system FF FS Output video frame 1 1 Video frame 1 and video frame 2 are output in this order (1,2 sequence). 1 0 Video frame 2 and video frame 1 are output in this order (2,1 sequence). 0 1 Video frame 1 is output twice. 0 0 Video frame 2 is output twice.
but this is for 720p (smpte 370m), not 720i.
follow-up: 14 comment:13 by , 8 years ago
Replying to cehoyos:
I attached a sample for testing sop_DVCProHD_test.mov.
Can you test if popular players (Edius, Adobe Premiere, Final Cut) interpret this file as TFF or BFF?
sorry, I can check it only visual, now I understand I couldn't say they "interpret file as TFF". All I can say, they show fields correctly.
I have remuxed sop_DVCProHD_test.mov into avi (with -vcodec copy) and watched in Adobe Premiere. The fields are still shown correctly. So, this is not because of the container's priority.
follow-up: 16 comment:14 by , 8 years ago
Replying to Aleksandr_Slobodeniuk:
Replying to cehoyos:
I attached a sample for testing sop_DVCProHD_test.mov.
Can you test if popular players (Edius, Adobe Premiere, Final Cut) interpret this file as TFF or BFF?
sorry, I can check it only visual
Is it possible to test the two files I attached visually or are they too short?
comment:15 by , 8 years ago
Status: | new → open |
---|
comment:16 by , 8 years ago
Replying to cehoyos:
Is it possible to test the two files I attached visually or are they too short?
What you want to know wrom this test - is if Adobe Premiere gets field interlace from the container. So, answering this question I have tested the whole video with avi container, that doesn't store field interlace information. The video was shown correctly.
comment:17 by , 8 years ago
Feel free to explain what ffmbc does, feel free to add links, please do not post code under license stricter than LGPL here.
comment:18 by , 8 years ago
useful information from ffmbc:
commit "dvenc: correctly set interlaced and tff bits"
https://github.com/bcoudurier/FFmbc/commit/736133a20bf6fab65b06f447e07b6b91fcdc0270
take a look at dv.c:459.
ffmbc does exactly what author of this bug were writing about: when it's decoding HD, it flips "fs" flag.
Unfortunately, I can't find the explanation of this action in SMPTE.
comment:19 by , 7 years ago
Possibly related sample from http://ffmpeg.org/pipermail/libav-user/2017-May/010366.html:
http://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket5092/
comment:20 by , 5 years ago
Resolution: | → fixed |
---|---|
Status: | open → closed |
This should be fixed after 33203a08e0a26598cb103508327a1dc184b27bc6
https://patchwork.ffmpeg.org/patch/15031/
though there is a problem with 16:9 when you open it in ffplay... (in particular the one file from #1370). Which is a problem.
This should fix it...