Handling PAFF encoded interlaced h264 files

Questions and answers on how to get the most out of FFAStrans
silicontrip
Posts: 54
Joined: Thu Sep 22, 2016 7:12 am

Handling PAFF encoded interlaced h264 files

Post by silicontrip »

Hi Steinar,

This is a known bug in ffmpeg, that it incorrectly reports the frame rate and interlacing for PAFF encoded h264 files. This includes the FFMpegSource filter for avisynth.
I've been able to get ffmpeg to correctly process them by forcing the frame rate and interlace modes.

I've been only able to detect these files with mediainfo, it correctly reports the intelace and also reports a different frame rate from the original frame rate.

Code: Select all

Frame rate                               : 50.000 fps
Original frame rate                      : 25.000 fps
Standard                                 : NTSC
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Interlaced
Scan order                               : Top Field First
don't ask me why media info says NTSC.

The relevant variables in ffastrans say:

Code: Select all

%f_frame_rate%=50
%i_interlace%=0
Is there a way of getting variables that are set via mediainfo rather than ffmpeg? So I can build a workflow to handle them?
Thanks
Mark
admin
Site Admin
Posts: 1687
Joined: Sat Feb 08, 2014 10:39 pm

Re: Handling PAFF encoded interlaced h264 files

Post by admin »

Thanks for reporting. I will try and get a hold of some PAFF encoded files so I can investigate. Or if you have some then please share ;-)

Currently, the variables are fixed in the method that has been programmed. But in the next version (0.8.0) you can pipe an mediainfo output to text file, read that file as a variable, search for specific text in the variable and act on that.

-steinar
silicontrip
Posts: 54
Joined: Thu Sep 22, 2016 7:12 am

Re: Handling PAFF encoded interlaced h264 files

Post by silicontrip »

A sample PAFF file https://dl.dropboxusercontent.com/u/234 ... rs2-08.mp4
This has been reported as an FFMPEG bug; https://trac.ffmpeg.org/ticket/5794
The only way to work around it is to detect correct interlace mode and incorporate it into a workflow.

Out of interest mediainfo can write to an XML file, it would be good to be able to parse this and access the XML nodes as variables.
admin
Site Admin
Posts: 1687
Joined: Sat Feb 08, 2014 10:39 pm

Re: Handling PAFF encoded interlaced h264 files

Post by admin »

Ok, I've looked at the file and it seem to be badly encoded. It looks interlaced but every frame is somewhat duplicated so the result video is fubar unless you strip every second frame. Forcing it to 25 will only resolve in corrupted interlacing information. So ffmpeg does not seem to correctly deal with this clip no matter what. Even if you got the right interlacing and fps information, it would not be processed properly in FFAStrans without some wizardry. And as a curiosity, Premiere reports the file as being 12.5 fps and jumps back and forth on playback. Quicktime Player also exhibit similar behavior on playback but reports 50 fps. So, are you sure PAFF is the only problem with this file?

-steinar
silicontrip
Posts: 54
Joined: Thu Sep 22, 2016 7:12 am

Re: Handling PAFF encoded interlaced h264 files

Post by silicontrip »

it could be that there are incorrect settings on the encoder, libx264 does not have the option for PAFF files, so it would have to be mainconcept, I didn't think it was possible to configure mainconcept to produce a corrupt file.

I'm not sure what to make of the file, I have a command line ffmpeg which encodes it properly. I did steal some of these switches from ffastrans ;-)

Code: Select all

ffmpeg -top 1 -i m-mh-ford-owners2-08.mp4 -vf pad=max(iw\,ih*(16/9)/sar):sar*ow/(16/9):sar*(ow-iw)/2:(oh-ih)/2,format=pix_fmts=yuv420p,scale=1440:1080:interl=1,setsar=4/3 -r 25 -map 0:v -c:v mpeg2video -pix_fmt yuv420p -color_range 1 -color_primaries 1 -color_trc 1 -colorspace 1 -dc 10 -intra_vlc 1 -b:v 35M -maxrate 35M -bufsize 12478054 -rc_init_occupancy 12478054 -sc_threshold 1000M -bf 2 -aspect 16:9 -qscale:v 1 -qmin:v 1 -g 12 -filter_complex [0:a]pan=1|c0=c0[a1],[0:a]pan=1|c0=c1[a2],[0:a]pan=1|c0=c2[a3],[0:a]pan=1|c0=c3[a4],[a1][a2][a3][a4]amerge=inputs=4[aud] -map [aud] -acodec pcm_s16le -ar 48000 -flags +ildct+ilme -top 1 107.mxf
QuicktimeX and AME appear to deal with it as fields, vertically interpolating the resulting file and with excessive flicker.

VLC seems to interpret it correctly but needs to have deinterlacing forced on. It also reports 50fps in the "Media Information / Codec" tab but is clearly playing the file as 25fps interlaced.

ffprobe says 50fps but the pts/dts timestamps in the show_frames output work out to 25fps

Unfortunately the only other PAFF files I have are from the same source and are encoded the same way. I think AME uses mainconcept I'll see if I can encode some files for testing.
silicontrip
Posts: 54
Joined: Thu Sep 22, 2016 7:12 am

Re: Handling PAFF encoded interlaced h264 files

Post by silicontrip »

I've encoded a PAFF file and I don't get the observed differences in frame rate and original frame rate from media info. Also mediainfo reporting the standard as NTSC might be indicative of other encoding errors.

So there is something funky with the PAFF files from that source.
silicontrip
Posts: 54
Joined: Thu Sep 22, 2016 7:12 am

Re: Handling PAFF encoded interlaced h264 files

Post by silicontrip »

Actually the file I've encoded is reported as progressive by FFAStrans but interlaced by mediaencoder. The resulting file "appears" ok, but has been encoded as progressive. I'm sure this could cause problems further down the workflow.

I'll put a file up later.
silicontrip
Posts: 54
Joined: Thu Sep 22, 2016 7:12 am

Re: Handling PAFF encoded interlaced h264 files

Post by silicontrip »

I found out that these clips were created with Sony Vegas. The problem appears to be with Sony Vegas h264 encoder. It uses the main concept h264 encoder. I've spent a few hours trying to encode an interlaced compatible clip without success.

The above clip was encoded with Adobe Media Encoder (AME) which also uses the main concept encoder but seems to produce a working clip.

I doubt I'll be able to get Vegas to acknowledge a problem.
silicontrip
Posts: 54
Joined: Thu Sep 22, 2016 7:12 am

Re: Handling PAFF encoded interlaced h264 files

Post by silicontrip »

I've encoded a file myself from Vegas (there appears to be no option to encode MBAFF) and made it available here;
https://dl.dropboxusercontent.com/u/234 ... g_test.mp4
Post Reply