Using ffmpeg to halve frame rate

Anthony Kehoe garion at aloria.net
Sun Apr 15 09:47:54 PDT 2018


I actually worked on this on Friday. I do a lot of work with ffmpeg to
get encodes working nicely with my 4K telly along with putting things
in iTunes for the AppleTVs.

I added a new option for my copy of get_iplayer, akfps, that changes
the ffmpeg resolutions should a 50fps version be downloaded.

        # Recording
        akfps           => [ 1, "akfps!", 'Recording', '--akfps', "AK:
Turn on ffmpeg override for 50fps to 25fps conversion"],

Down in sub postproc, I modified the section where @codec_opts builds
the video/audio codec options. I looked at a few BBC encodes and it
seems like they use a bitrate around 2285 with a maxrate of 3500 for
hls streams:

Bit rate mode                            : Variable
Bit rate                                 : 2 335 kb/s
Maximum bit rate                         : 3 500 kb/s
Width                                    : 1 280 pixels
Height                                   : 720 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 25.000 FPS

Therefore, I used a target bitrate of 2285 with a maximum of 3500.

        if ( ! $opt->{ffmpegobsolete} ) {
                if ( $opt->{akfps} && $prog->{mode} =~
/(hvfhd|dvfhd|hvfsd|dvfsd|hvfhigh|dvfhigh)/ ) {
                        push @codec_opts, ( '-r', '25', '-b:v',
'2285k', '-maxrate', '3.5M', '-c:a', 'copy' );
                } else {
                        push @codec_opts, ( '-c:v', 'copy', '-c:a', 'copy' );
                }
        } else {
                if ( $opt->{akfps} && $prog->{mode} =~
/(hvfhd|dvfhd|hvfsd|dvfsd|hvfhigh|dvfhigh)/ ) {
                        push @codec_opts, ( '-r', '25', '-b:v',
'2285k', '-maxrate', '3.5M', '-acodec', 'copy' );
                } else {
                        push @codec_opts, ( '-vcodec', 'copy',
'-acodec', 'copy' );
                }
        }

This re-encodes the video, so be warned it increases the amount of
time to process downloads. On the system I use the encode gets around
70fps so a 60 minute programme takes around 25 minutes to re-encode. I
modified the code this way so that the final tagging process is
unaffected. In addition, it only executes on 50fps streams and I took
dinky's advice in the squarepenguin forum to set the stream options to
get hls if available and fall-back to hvf.

On 15 April 2018 at 09:43, Anthony Kehoe <garion at aloria.net> wrote:
> I actually worked on this on Friday. I do a lot of work with ffmpeg to get
> encodes working nicely with my 4K telly along with putting things in iTunes
> for the AppleTVs.
>
> I added a new option for my copy of get_iplayer, akfps, that changes the
> ffmpeg resolutions should a 50fps version be downloaded.
>
>         # Recording
>         akfps           => [ 1, "akfps!", 'Recording', '--akfps', "AK: Turn
> on ffmpeg override for 50fps to 25fps conversion"],
>
> Down in sub postproc, I modified the section where @codec_opts builds the
> video/audio codec options. I looked at a few BBC encodes and it seems like
> they use a bitrate around 2285 with a maxrate of 3500 for hls streams:
>
> Bit rate mode                            : Variable
> Bit rate                                 : 2 335 kb/s
> Maximum bit rate                         : 3 500 kb/s
> Width                                    : 1 280 pixels
> Height                                   : 720 pixels
> Display aspect ratio                     : 16:9
> Frame rate mode                          : Constant
> Frame rate                               : 25.000 FPS
>
> Therefore, I used a target bitrate of 2285 with a maximum of 3500.
>
>         if ( ! $opt->{ffmpegobsolete} ) {
>                 if ( $opt->{akfps} && $prog->{mode} =~
> /(hvfhd|dvfhd|hvfsd|dvfsd|hvfhigh|dvfhigh)/ ) {
>                         push @codec_opts, ( '-r', '25', '-b:v', '2285k',
> '-maxrate', '3.5M', '-c:a', 'copy' );
>                 } else {
>                         push @codec_opts, ( '-c:v', 'copy', '-c:a', 'copy'
> );
>                 }
>         } else {
>                 if ( $opt->{akfps} && $prog->{mode} =~
> /(hvfhd|dvfhd|hvfsd|dvfsd|hvfhigh|dvfhigh)/ ) {
>                         push @codec_opts, ( '-r', '25', '-b:v', '2285k',
> '-maxrate', '3.5M', '-acodec', 'copy' );
>                 } else {
>                         push @codec_opts, ( '-vcodec', 'copy', '-acodec',
> 'copy' );
>                 }
>         }
>
> This re-encodes the video, so be warned it increases the amount of time to
> process downloads. On the system I use the encode gets around 70fps so a 60
> minute programme takes around 25 minutes to re-encode. I modified the code
> this way so that the final tagging process is unaffected. In addition, it
> only executes on 50fps streams and I took dinky's advice in the
> squarepenguin forum to set the stream options to get hls if available and
> fall-back to hvf.
>
> On 15 April 2018 at 09:18, RS <richard22j at zoho.com> wrote:
>>
>> A couple of years ago there were problems with HLS and there was
>> speculation that we might have 50 fps HVFhd and DVFhd as the only HD modes.
>> At that time I wondered if it would be feasible to drop every other frame to
>> reduce the frame rte to 25 fps.  I thought because of the H.264 delta
>> encoding it would probably mean transcoding and that it would be too slow.
>>
>> On a 42" screen for the programmes that I usually watch I cannot see any
>> difference between a HD picture at 50 fps and one at 25 fps, so 50 fps for
>> me is just a waste of bandwidth and storage space, so I have been looking at
>> it again.
>>
>> The ffmpeg documentation
>> https://www.ffmpeg.org/ffmpeg.html#toc-Video-Options
>>
>> at 5.5 Video Options says for -r
>> "As an output option, duplicate or drop input frames to achieve constant
>> output frame rate fps."
>>
>> That would be very useful if it means there is no need for transcoding.
>>
>> I found this example.
>>
>> https://stackoverflow.com/questions/45462731/using-ffmpeg-to-change-framerate?rq=1
>>
>> The command I used for the first suggestion, with re-encoding, was
>>
>> ffmpeg -i am.mp4 -vf "setpts=PTS" -f 25 am4.mp4
>>
>> That worked and kept the audio.  It was slow, taking about 1.5 times real
>> time.  Also the bit rate at about 1.4Mbit/s was only about two-thirds of
>> what I was expecting, so it may have been more compressed than the original.
>> I had first tried "setpts=0.5*PTS" but that produced a file which played at
>> twice speed and "setpts=2*PTS" which played at half speed.
>>
>> For the second example without re-encoding my commands were
>>
>> ffmpeg -i am.mp4 -c copy -f h264 am1.h264
>> ffmpeg -i am1.h264 -c copy -r 25 am2.mp4
>>
>> There was no audio, although that can be added back later.  It was quite
>> quick, at about a fiftieth of real time.  It did not achieve any reduction
>> in file size or bit rate. and the frame rate remained at 50 fps, so the -r
>> 25 had been ignored.  I did get lots of error messages saying "pts has no
>> value" so maybe I need to set that.  I did try repeating the -vf parameter
>> from the first command it said,
>>
>> Filtergraph 'setpts=PTS' was defined for video output stream 0:0 but codec
>> copy was selected.
>> Filtering and streamcopy cannot be used together.
>>
>> The second example from the stackoverflow page placed the parameter -r=25
>> before -i.  I tried that.  There was no reduction in file size but the time
>> was made twice as long and the file played at half speed.  As I understand
>> it, placing the parameter in that position made it an input option.
>>
>> Has anyone managed to get ffmpeg to halve the frame rate without
>> re-encoding?  Can it be applied to the raw .ts output?
>>
>> Best wishes
>> Richard
>>
>>
>> _______________________________________________
>> get_iplayer mailing list
>> get_iplayer at lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/get_iplayer
>
>



More information about the get_iplayer mailing list