Page 1 of 2

ffmpeg frame rate incorrect

PostPosted: Thu Mar 19, 2015 6:54 pm
by compi
ffmpeg transcoded .ts files with an incorrect frame rate

Media Info
  Code:
Allgemein
ID                                       : 32776 (0x8008)
Vollständiger Name                       : W:\video\Serien\The Walking Dead\Season 5\The Walking Dead - S05E14 Falsches Licht.ts
Format                                   : MPEG-TS
Dateigröße                               : 2,75 GiB
Dauer                                    : 40min
Modus der Gesamtbitrate                  : variabel
Gesamte Bitrate                          : 9 685 Kbps

Video
ID                                       : 1023 (0x3FF)
Menü-ID                                  : 132 (0x84)
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format-Profil                            : High@L4.0
Format-Einstellungen für CABAC           : Ja
Format-Einstellungen für ReFrames        : 3 frames
Codec-ID                                 : 27
Dauer                                    : 40min
Bitrate                                  : 8 818 Kbps
Breite                                   : 1 920 Pixel
Höhe                                     : 1 080 Pixel
Bildseitenverhältnis                     : 16:9
Bildwiederholungsrate                    : 25,000 FPS
Standard                                 : Component
ColorSpace                               : YUV
ChromaSubsampling                        : 4:2:0
BitDepth/String                          : 8 bits
Scantyp                                  : Interlaced
Scanreihenfolge                          : oberes Feld zuerst
Bits/(Pixel*Frame)                       : 0.170
Stream-Größe                             : 2,51 GiB (91%)
colour_primaries                         : BT.709
transfer_characteristics                 : BT.709
matrix_coefficients                      : BT.709
colour_range                             : Limited

Audio
ID                                       : 1027 (0x403)
Menü-ID                                  : 132 (0x84)
Format                                   : AC-3
Format/Info                              : Audio Coding 3
Format_Settings_ModeExtension            : CM (complete main)
Format-Einstellungen für Endianess       : Big
Codec-ID                                 : 6
Dauer                                    : 40min
Bitraten-Modus                           : konstant
Bitrate                                  : 384 Kbps
Kanäle                                   : 6 Kanäle
Kanal-Positionen                         : Front: L C R, Side: L R, LFE
Samplingrate                             : 48,0 KHz
BitDepth/String                          : 16 bits
Video Verzögerung                        : 16ms
Stream-Größe                             : 112 MiB (4%)
Sprache                                  : Deutsch


ffmpeg
  Code:
ffmpeg -threads auto -i /../../mnt/Raid/media/video/Serien/The Walking Dead/Season 5/The Walking Dead - S05E14 Falsches Licht.ts -y -threads auto -c:v mpeg2video -pix_fmt yuv420p -b:v 8000k -maxrate:v 8000k -bufsize:v 8000k -r 50 -g 15 -c:a ac3 -b:a 192k -ac 2 -map 0:0 -map 0:1 -sn -f mpegts /temp/Serviio/transcoding-temp-812-kirch-ORIGINAL.stf


Serviio PRO 1.5.1
Ubuntu 14.04


ffmpeg
  Code:
lars@ubuntu:~$ ffmpeg
ffmpeg version 2.6 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
  configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvo-aacenc --enable-libvidstab
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

Re: ffmpeg frame rate incorrect

PostPosted: Mon Mar 23, 2015 8:14 pm
by zip
Can you post ffmpeg -i for the file?

Re: ffmpeg frame rate incorrect

PostPosted: Tue Mar 24, 2015 8:21 am
by compi
  Code:
lars@ubuntu:/mnt/Raid/media/video/Serien/The Walking Dead/Season 5$ ffmpeg -i *S05E14*.ts
ffmpeg version 2.6 Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
  configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvo-aacenc --enable-libvidstab
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
[h264 @ 0x20d3160] mmco: unref short failure
    Last message repeated 1 times
[h264 @ 0x20d3160] number of reference frames (0+4) exceeds max (3; probably corrupt input), discarding one
[h264 @ 0x20d3160] mmco: unref short failure
    Last message repeated 1 times
[h264 @ 0x20d3160] number of reference frames (0+4) exceeds max (3; probably corrupt input), discarding one
Input #0, mpegts, from 'The Walking Dead - S05E14 Falsches Licht.ts':
  Duration: 00:40:42.45, start: 54119.605378, bitrate: 9684 kb/s
  Program 132
    Stream #0:0[0x3ff]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x403](deu): Audio: ac3 ([6][0][0][0] / 0x0006), 48000 Hz, 5.1(side), fltp, 384 kb/s
At least one output file must be specified



compi

Re: ffmpeg frame rate incorrect

PostPosted: Sun Mar 29, 2015 7:21 pm
by zip
Seriio uses the tbr field (when available) to get the frame rate. According to his, it's the most reliable: http://stackoverflow.com/questions/9399 ... p-prop-fps

Re: ffmpeg frame rate incorrect

PostPosted: Mon Mar 30, 2015 9:37 pm
by jhb50
file is interlaced so frame rate doubles

Re: ffmpeg frame rate incorrect

PostPosted: Wed Apr 01, 2015 4:50 pm
by zip
yeah, I thought so, but I don't think I can say that from the ffmpeg output

Re: ffmpeg frame rate incorrect

PostPosted: Fri Apr 03, 2015 5:14 pm
by compi
it is possible to transcode hard in to 25fps?

Re: ffmpeg frame rate incorrect

PostPosted: Sat Apr 04, 2015 3:00 am
by jhb50
Could you post your .ts file? You could use tsmuxer to cut the first 20 seconds from it to make that smaller.

I ask because I think there are problems with serviio handling interlaced files but yours appears different with a tbr = 2x fps and I need it to test further.

Re: ffmpeg frame rate incorrect

PostPosted: Sun Apr 05, 2015 10:30 pm
by jhb50
Further to my last post...

I'd like to know where this file came from because 2 things about it are strange.
(1) the tbr of 50 when fps is 25 and (2) the mediainfo scan type showing "interlaced".

In my experience the 50 tbr only occurs when a file has been transcoded to 50 fps, and mediainfo only displays scan type "MDAFF" when an AVC video file is interlaced. So why is this file different?

I have done further testing and cannot replicate the posted output so I would like to test the actual file, and know how it was created (direct capture, download, transcode etc).

Then I will be able to comment more on the Serviio transcoding and the ability/impact of hard transcode to 25 fps.

Re: ffmpeg frame rate incorrect

PostPosted: Mon Apr 06, 2015 3:58 pm
by compi
the file to record with vdr and then cut with ts doctor .

I'll upload the file straight up and then send a PM .

compi

Re: ffmpeg frame rate incorrect

PostPosted: Mon Apr 06, 2015 7:17 pm
by jhb50
Great. vrd?? Did you mean dvr? Which dvr do you use?

Re: ffmpeg frame rate incorrect

PostPosted: Mon Apr 06, 2015 7:28 pm
by compi

Re: ffmpeg frame rate incorrect

PostPosted: Wed Apr 15, 2015 11:37 pm
by jhb50
I am still working on this, but I cannot find a Serviio profile that would have generated the transcoding command you have posted in particular the 8000k limit. What device profile were you using?

@zip Do you add an upper mpeg2video limit when the source file exceeds -b:V 8000K. This source is -b:V 17200K.

  Code:
ffmpeg -threads auto -i /../../mnt/Raid/media/video/Serien/The Walking Dead/Season 5/The Walking Dead - S05E14 Falsches Licht.ts -y -threads auto -c:v mpeg2video -pix_fmt yuv420p -b:v 8000k -maxrate:v 8000k -bufsize:v 8000k -r 50 -g 15 -c:a ac3 -b:a 192k -ac 2 -map 0:0 -map 0:1 -sn -f mpegts /temp/Serviio/transcoding-temp-812-kirch-ORIGINAL.stf

Re: ffmpeg frame rate incorrect

PostPosted: Thu Apr 16, 2015 2:37 pm
by compi
I modified the Samsung profile . I have limited the bandwidth to 8000

Re: ffmpeg frame rate incorrect

PostPosted: Thu Apr 16, 2015 2:39 pm
by compi
<Profile id="kirch" name="(Kirchner)" extendsProfileId="1">
<ContentDirectoryMessageBuilder>org.serviio.upnp.service.contentdirectory.SamsungDLNAMessageBuilder</ContentDirectoryMessageBuilder>
<ResourceTransportProtocolHandler>org.serviio.upnp.protocol.http.transport.SamsungWiseLinkProtocolHandler</ResourceTransportProtocolHandler>
<Detection>
<UPnPSearch>
<FriendlyName>(^\[TV\][A-Z]{2}\d{2}(E|F)[A-Z]?\d{3,4}.*)|^\[TV\] Samsung</FriendlyName>
<ModelNumber>(1\.0)|(AllShare1\.0)</ModelNumber>
</UPnPSearch>
<HttpHeaders>
<!-- for BD players -->
<User-Agent>(.*SEC_HHP_BD-[EF].*)|(.*SEC_HHP_\[(HT|BD)\][EF].*)</User-Agent>
</HttpHeaders>
</Detection>
<DeviceDescription>
<ExtraElements>
&lt;sec:ProductCap&gt;smi,DCM10,getMediaInfo.sec,getCaptionInfo.sec&lt;/sec:ProductCap&gt;
&lt;sec:X_ProductCap&gt;smi,DCM10,getMediaInfo.sec,getCaptionInfo.sec&lt;/sec:X_ProductCap&gt;
</ExtraElements>
</DeviceDescription>
<MediaFormatProfiles>
<MediaFormatProfile mime-type="video/x-mkv">MATROSKA</MediaFormatProfile>
<MediaFormatProfile mime-type="video/x-msvideo" name="">AVI</MediaFormatProfile>
<MediaFormatProfile mime-type="audio/x-flac">FLAC</MediaFormatProfile>
</MediaFormatProfiles>
<ContentDirectoryDefinitionFilter>org.serviio.upnp.service.contentdirectory.definition.SamsungContentDirectoryDefinitionFilter</ContentDirectoryDefinitionFilter>
<H264LevelCheck>FILE_ATTRIBUTES</H264LevelCheck>
<Transcoding>
<!-- Transcode all videos with MPEG2VIDEO and ac3 audio transcoding -->
<Video targetContainer="mpegts" targetVCodec="mpeg2video" maxVBitrate="8000" targetACodec="ac3" aBitrate="192" forceInheritance="true">

<Matches container="*" />
</Video>
<Audio targetContainer="lpcm" forceInheritance="true">
<Matches container="mp4" />
<Matches container="ogg" />
<Matches container="adts" />
<Matches container="mp2" />
<Matches container="wavpack" />
<Matches container="mpc" />
<Matches container="ape" />
<Matches container="asf" />
</Audio>
</Transcoding>
<OnlineTranscoding>
<Video targetContainer="mpegts" maxVBitrate="8000" targetACodec="ac3" aBitrate="384">
<Matches container="applehttp" vCodec="h264"/>
</Video>
<Video targetContainer="mpegts" targetVCodec="mpeg2video" maxVBitrate="8000" targetACodec="ac3" aBitrate="384">
<Matches container="asf" /> <!-- mms -->
<Matches container="flv" /> <!-- transcoding all flv streams, even h264, to avoild premature disconnects, to avoid this, use Samsung C/D profile -->
</Video>
</OnlineTranscoding>
<AutomaticImageRotation>true</AutomaticImageRotation>
<LimitImageResolution>false</LimitImageResolution>
<Subtitles>
<SoftSubs mime-type="smi/caption" />
</Subtitles>
<ThumbnailsResolution>HD</ThumbnailsResolution>
</Profile>

Re: ffmpeg frame rate incorrect

PostPosted: Fri Apr 24, 2015 1:59 am
by jhb50
To summarize, I was interested in this post because I had not seen differing fps and tbr values from ffmpeg; questioned the use of -r 50 in the ffmpeg command; and could not find the use of maxVbitrate=8000 in any Serviio profile.

Here are the results of my analysis:

1) The "25fps,50tbr" ffmpeg result is correct and indicates the file "The Walking Dead - S05E14 Falsches Licht.ts" which was captured from a TV broadcast is a 25fps h264 Progressive Segmented File (PsF).

PsF means an original 25fps progressive frame has been encoded as "interlaced" and the 2 fields in each 25 fps frame contain the even and odd lines of the original "progressive" frame but both fields have the same time stamp rather than the 1/25sec difference in field timestamps that normal interlaced fields would have . The h264 specs D.9.2 provide for this - "When clockTimestamp is equal for two fields of opposite parity that are consecutive in output order, both with ct_type equal to 0 (progressive) or ct_type equal to 2 (unknown),the two fields are indicated to have come from the same original progressive frame."
These PsF files are created at the source by the cameras and are used by broadcasters to transmit "progressive" material over systems built to work with "interlaced", in this case the TV broadcast captured by vdr (http://www.tvdr.de). (See http://wolfcrow.com/blog/understanding- ... rames-psf/)

FFmpeg recognizes h264 PsF files by showing the tbr as twice the fps eg: "25 fps, 50 tbr"
(http://forum.videohelp.com/threads/3523 ... l-in-h-264). FFMPEG will also transcode the file by default at 25fps which shows it uses its fps value rather than the tbr value.

Note that I have found no way to create these PsF files with software. The X264 encoder option "fake-interlaced" will create interlaced flagged files for authoring Blu-ray disks with 25p and 29.97p material however they contain the original progressive frames rather than the 2 interlaced fields, and ffmpeg will report them with equal fps and tbr values. (http://www.x264bluray.com/home/1080i-p)

2) The use of tbr and -r 50 by Serviio is incorrect.

As Zip has indicated above, Serviio uses "tbr" to determine the correct frame rate. Hence the ffmpeg command generated from the custom profile above contains -r 50 which results in a transcode to a 50 fps,50 tbr progressive video. Analysis shows each progressive frame consists of the interweaved odd and even field lines, and every second frame is duplicated. This shows that ffmpeg recognizes the file as 25 fps interlaced, and duplicates each 25fps frame in order to get the output frame rate to 50fps. Similarly by removing the -r 50 and letting ffmpeg default to the existing timestamps, produces a 25fps, 25 tbr progressive video. These both show the use of tbr is incorrect, and that ffmpeg itself uses the fps value.

Note that Zips justification for using tbr is from a post using 2011 fmpeg on "network camera" video. I would also refer to a 2010 post https://forums.creativecow.net/thread/291/140 which also suggests tbr is the most accurate but also suggests "You can always just exclude the -r flag and the frame rates will pass from source to destination". Given the changes to ffmpeg over the past few years including the PsF support added in 2013, and the current ffmpeg action to correctly default to the fps value, I have opened a ticket suggesting that Serviio never force the output frame rate, but rather let ffmpeg default to the existing input timestamps.

3) The use of a custom profile by the poster to transcode his files to maxVbitrate=8000K mpeg2video seems unwarranted since I have verified the Samsung will play the original avc codec without delay and without the quality loss of transcoding.

Re: ffmpeg frame rate incorrect

PostPosted: Fri Apr 24, 2015 12:11 pm
by zip
Great write-up. I will look at the ticket for a future release, thanks.

Re: ffmpeg frame rate incorrect

PostPosted: Tue May 26, 2015 8:04 am
by Koniec12
Interesting stuff. Learned a lot from it. Thanks:)

Re: ffmpeg frame rate incorrect

PostPosted: Tue Mar 29, 2016 9:21 am
by compi
thanks it works with ver. 1.6


compi

Gesendet von meinem Xperia Z Ultra mit Tapatalk

Re: ffmpeg frame rate incorrect

PostPosted: Fri Apr 08, 2016 6:23 pm
by jhb50
??? What works with 1.6??