Discussion:
Using ffmpeg to halve frame rate
RS
2018-04-15 16:18:08 UTC
Permalink
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
Anthony Kehoe
2018-04-15 16:47:54 UTC
Permalink
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.
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"],
video/audio codec options. I looked at a few BBC encodes and it seems like
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)/ ) {
'-maxrate', '3.5M', '-c:a', 'copy' );
} else {
);
}
} else {
if ( $opt->{akfps} && $prog->{mode} =~
/(hvfhd|dvfhd|hvfsd|dvfsd|hvfhigh|dvfhigh)/ ) {
'-maxrate', '3.5M', '-acodec', 'copy' );
} else {
'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.
Post by RS
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
http://lists.infradead.org/mailman/listinfo/get_iplayer
RS
2018-04-16 10:37:34 UTC
Permalink
Post by Anthony Kehoe
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
Turn on ffmpeg override for 50fps to 25fps conversion"],
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
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.
Thanks, that's useful. -b:v=2285k does indeed give me the bit rate I was
expecting.

For the moment I want to try to reduce the frame rate by dropping
alternate frames as that should avoid any loss of quality in
re-encoding. Also I want to be able to do it in a reasonable time on
this ancient desktop which has a 2.3GHz Core 2 duo.

I gather -r in ffmpeg does not work with -c copy. According to this
article there is a workaround by concatenating a dummy file at the
beginning to set the PTS value. I'll give it a try.

https://superuser.com/questions/1088382/change-framerate-in-ffmpeg-without-reencoding

Best wishes
Richard
Nick Payne
2018-04-15 20:59:47 UTC
Permalink
Post by RS
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.
I experimented a while ago with running some GiP downloads through
Handbrake to convert the video to the x265 codec. That reduced the file
size to about 1/3 of the original download, with no subjective
difference in video quality that I could see when viewing on our TV. A
one hour 1280x720 25fps program that downloads as a 1Gb file was reduced
in size to ~350Mb. On my PC, the re-encode runs at about 50fps for
1280x720, so ~2x real time for 25fps and ~real time for 50fps. For
smaller video dimension such as 960x540, the re-encode speed was around
85-90FPS.

Nick
Steve Dodd
2018-04-16 07:21:08 UTC
Permalink
Post by Nick Payne
I experimented a while ago with running some GiP downloads through
Handbrake to convert the video to the x265 codec. That reduced the file
size to about 1/3 of the original download, with no subjective
difference in video quality that I could see when viewing on our TV.
Figures - most of the comparison work done on H.265 v. H.264 says you
should get same subjective quality for half the bitrate.
Post by Nick Payne
A one hour 1280x720 25fps program that downloads as a 1Gb file was reduced
in size to ~350Mb. On my PC, the re-encode runs at about 50fps for
1280x720, so ~2x real time for 25fps and ~real time for 50fps. For
smaller video dimension such as 960x540, the re-encode speed was around
85-90FPS.
Do you know what x265 quality setting you used? I'm also experimenting
now it seems HLSHD is being turned off (series 2 of Salamander has HVF
only so far).. RF17 seems to be spitting about half the bitrate of the
BBC h.264 output, and running at ~40fps which I can live with (Core
i5-6500). Noticeable quality difference still when looking at stills,
but have tried watching it moving yet..

Incidentally, has anyone else noticed HE-AAC coming through in the
downloads recently?

S.
Nick Payne
2018-04-16 08:27:09 UTC
Permalink
Post by Steve Dodd
Post by Nick Payne
I experimented a while ago with running some GiP downloads through
Handbrake to convert the video to the x265 codec. That reduced the file
size to about 1/3 of the original download, with no subjective
difference in video quality that I could see when viewing on our TV.
Figures - most of the comparison work done on H.265 v. H.264 says you
should get same subjective quality for half the bitrate.
Post by Nick Payne
A one hour 1280x720 25fps program that downloads as a 1Gb file was reduced
in size to ~350Mb. On my PC, the re-encode runs at about 50fps for
1280x720, so ~2x real time for 25fps and ~real time for 50fps. For
smaller video dimension such as 960x540, the re-encode speed was around
85-90FPS.
Do you know what x265 quality setting you used? I'm also experimenting
now it seems HLSHD is being turned off (series 2 of Salamander has HVF
only so far).. RF17 seems to be spitting about half the bitrate of the
BBC h.264 output, and running at ~40fps which I can live with (Core
i5-6500). Noticeable quality difference still when looking at stills,
but have tried watching it moving yet..
For re-encoding 1280x720 downloads to x265, on the Video tab in
Handbrake I have the encoder preset at "Faster" and the RF quality at 23.

Nick
RS
2018-04-16 11:12:10 UTC
Permalink
Post by Nick Payne
Post by Steve Dodd
Post by Nick Payne
I experimented a while ago with running some GiP downloads through
Handbrake to convert the video to the x265 codec. That reduced the file
size to about 1/3 of the original download, with no subjective
difference in video quality that I could see when viewing on our TV.
Figures - most of the comparison work done on H.265 v. H.264 says you
should get same subjective quality for half the bitrate.
Post by Nick Payne
A one hour 1280x720 25fps program that downloads as a 1Gb file was reduced
in size to ~350Mb. On my PC, the re-encode runs at about 50fps for
1280x720, so ~2x real time for 25fps and ~real time for 50fps. For
smaller video dimension such as 960x540, the re-encode speed was around
85-90FPS.
Do you know what x265 quality setting you used? I'm also experimenting
now it seems HLSHD is being turned off (series 2 of Salamander has HVF
only so far).. RF17 seems to be spitting about half the bitrate of the
BBC h.264 output, and running at ~40fps which I can live with (Core
i5-6500). Noticeable quality difference still when looking at stills,
but have tried watching it moving yet..
For re-encoding 1280x720 downloads to x265, on the Video tab in
Handbrake I have the encoder preset at "Faster" and the RF quality at 23.
I tried using ffmpeg and the libx265 codec with default quality
(CRF=28?) on HVFhd. I only did half a minute because it was so slow.
It is convenient to do it on this machine, but it has only got a 2.3GHZ
Core 2 duo. I set -r=25 to reduce the frame rate to 25fps by dropping
alternate frames. It confirmed that dropping frames worked, and I did
not notice any problems as a result. It only processed 2 frames a
second, so an hour's recording would take 12 hours! I'll have to try it
on my latest laptop which has a core i5-7200U.

Best wishes
Richard
RS
2018-04-16 09:03:33 UTC
Permalink
Post by Steve Dodd
Incidentally, has anyone else noticed HE-AAC coming through in the
downloads recently?
Another advantage of HLShd was that there was no HE-AAC when the audio
was 96kbit/s. HVF has used HE-AAC with 96kbit/s audio for some time,
but only at the lower resolutions. I have not seen 96kbit/s audio and
HE-AAC at the higher HVF resolutions like HVFhd, HVFsd and HVFxsd. I
have only seen those resolutions with 128kbit/s or higher audio (usually
320kbit/s). As for DVF, I have not used it enough to be able to
comment. Have you seen HE-AAC with the higher resolutions?

Best wishes
Richard
Nick Payne
2018-04-17 21:27:38 UTC
Permalink
Post by Nick Payne
Post by RS
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.
I experimented a while ago with running some GiP downloads through
Handbrake to convert the video to the x265 codec. That reduced the file
size to about 1/3 of the original download, with no subjective
difference in video quality that I could see when viewing on our TV. A
one hour 1280x720 25fps program that downloads as a 1Gb file was reduced
in size to ~350Mb. On my PC, the re-encode runs at about 50fps for
1280x720, so ~2x real time for 25fps and ~real time for 50fps. For
smaller video dimension such as 960x540, the re-encode speed was around
85-90FPS.
I just ran another test on some 1280x720 50fps and 1280x720 25fps
downloads from the last UK snooker championship. As before, the 25fps
downloads were reduced to about 1/3 previous size by Handbrake (eg a
4h58m match that was 5.03Gb came down to 1.55Gb). However, the 50fps
downloads were reduced by far more with exactly the same settings in
Handbrake - for example, a 4h44m match that was a 10.2Gb download from
GiP came down to 1.48Gb, and a 4h14m 8.93Gb file came down to 1.30Gb.
This leads me to wonder if the 50fps downloads are from a 25fps original
and just have each frame duplicated, as after running through Handbrake,
the file sizes just seem proportional to the length of the program, and
whether 50fps or 25fps has no effect on the file size.

Nick
RS
2018-04-18 09:40:56 UTC
Permalink
Post by Nick Payne
I just ran another test on some 1280x720 50fps and 1280x720 25fps
downloads from the last UK snooker championship. As before, the 25fps
downloads were reduced to about 1/3 previous size by Handbrake (eg a
4h58m match that was 5.03Gb came down to 1.55Gb). However, the 50fps
downloads were reduced by far more with exactly the same settings in
Handbrake - for example, a 4h44m match that was a 10.2Gb download from
GiP came down to 1.48Gb, and a 4h14m 8.93Gb file came down to 1.30Gb.
This leads me to wonder if the 50fps downloads are from a 25fps original
and just have each frame duplicated, as after running through Handbrake,
the file sizes just seem proportional to the length of the program, and
whether 50fps or 25fps has no effect on the file size.
That's interesting. I did wonder how the BBC was generating its 50fps
material. It seemed surprising that it would shoot all its material at
a higher frame rate than broadcast just for the benefit of the iPlayer.

If I want to achieve a 50fps frame rate by duplicating frames I can do
that myself. For the BBC to duplicate frames is a waste of everyone's
time and bandwidth.

Best wishes
Richard

Loading...