Discussion:
[FFmpeg-user] framerate conversion with sync audio
Carles Vila
2016-10-11 21:25:58 UTC
Permalink
Hi, I'm trying to perform framerate conversion of a video, from 24fps to
25fps to be precise.
The source is mov, ProRes with multichannel audio at 48kHz.
It is mandatory for my application to preserve the integrity of all frames,
i.e. no frame-interpolation or duplication should occur.
In other words, just the playback speed should be increased from 24 to 25,
resulting in a video of slightly shorter duration.
I've been partially successful so far using the command

ffmpeg -r 25 -i <inputfile24fps.mov> -r 25 -c:v prores -profile:v 3 -c:a
pcm_s24le <output_25fps.mov>

This comand produces a good video, shorter than the original, but the
problem is with audio. As you can imagine, the audio drifts out of sync
because it has no knowledge of the video framerate conversion.
My solution now is to process the audio externally, in an audio editor. I
must apply a sample rate conversion, first forcing the sample rate metadata
to 50.000 Hz (48.000 *(25/24)) and then resampling at 48.000 Hz
This shortens the audio by the same amount as the video and can be merged
to it.
Is there any way to perform this audio processing within ffmpeg?
Thanks!


ffmpeg -r 25 -i input.mov -r 25 -c:v prores -profile:v 3 -c:a pcm_s24le
output_25fps.mov
ffmpeg version 2.7.2 Copyright (c) 2000-2015 the FFmpeg developers
built with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.7.2_1 --enable-shared
--enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables
--enable-avresample --cc=clang --host-cflags= --host-ldflags=
--enable-opencl --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc
--enable-libxvid --enable-libfreetype --enable-libvorbis --enable-libvpx
--enable-libass --enable-ffplay --enable-libfdk-aac --enable-libopus
--enable-libquvi --enable-libx265 --enable-libopenjpeg
--extra-cflags='-I/usr/local/Cellar/openjpeg/1.5.2_1/include/openjpeg-1.5 '
--enable-nonfree --enable-vda
libavutil 54. 27.100 / 54. 27.100
libavcodec 56. 41.100 / 56. 41.100
libavformat 56. 36.100 / 56. 36.100
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 16.101 / 5. 16.101
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 2.100 / 1. 2.100
libpostproc 53. 3.100 / 53. 3.100
Guessed Channel Layout for Input Stream #0.1 : mono
Guessed Channel Layout for Input Stream #0.2 : mono
Guessed Channel Layout for Input Stream #0.3 : mono
Guessed Channel Layout for Input Stream #0.4 : mono
Guessed Channel Layout for Input Stream #0.5 : mono
Guessed Channel Layout for Input Stream #0.6 : mono
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mov':
Metadata:
major_brand : qt
minor_version : 537199360
compatible_brands: qt
creation_time : 2016-10-11 12:30:25
Duration: 00:01:49.04, start: 0.000000, bitrate: 150503 kb/s
Stream #0:0(eng): Video: prores (apch / 0x68637061),
yuv422p10le(bt709), 1920x1080, 143548 kb/s, SAR 1:1 DAR 16:9, 24 fps, 24
tbr, 24 tbn, 24 tbc (default)
Metadata:
creation_time : 2016-10-11 12:30:25
handler_name : Apple Alias Data Handler
encoder : Apple ProRes 422 HQ
timecode : 00:00:00:00
Stream #0:1(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, 1
channels, s32 (24 bit), 1152 kb/s (default)
Metadata:
creation_time : 2016-10-11 12:30:25
handler_name : Apple Alias Data Handler
Stream #0:2(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, 1
channels, s32 (24 bit), 1152 kb/s (default)
Metadata:
creation_time : 2016-10-11 12:30:25
handler_name : Apple Alias Data Handler
Stream #0:3(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, 1
channels, s32 (24 bit), 1152 kb/s (default)
Metadata:
creation_time : 2016-10-11 12:30:25
handler_name : Apple Alias Data Handler
Stream #0:4(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, 1
channels, s32 (24 bit), 1152 kb/s (default)
Metadata:
creation_time : 2016-10-11 12:30:25
handler_name : Apple Alias Data Handler
Stream #0:5(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, 1
channels, s32 (24 bit), 1152 kb/s (default)
Metadata:
creation_time : 2016-10-11 12:30:25
handler_name : Apple Alias Data Handler
Stream #0:6(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, 1
channels, s32 (24 bit), 1152 kb/s (default)
Metadata:
creation_time : 2016-10-11 12:30:25
handler_name : Apple Alias Data Handler
Stream #0:7(eng): Data: none (tmcd / 0x64636D74) (default)
Metadata:
creation_time : 2016-10-11 12:32:09
handler_name : Apple Alias Data Handler
timecode : 00:00:00:00
File 'output_25fps.mov' already exists. Overwrite ? [y/N] y
Output #0, mov, to 'output_25fps.mov':
Metadata:
major_brand : qt
minor_version : 537199360
compatible_brands: qt
encoder : Lavf56.36.100
Stream #0:0(eng): Video: prores (apch) (apch / 0x68637061),
yuv422p10le, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 25 fps, 12800
tbn, 25 tbc (default)
Metadata:
creation_time : 2016-10-11 12:30:25
handler_name : Apple Alias Data Handler
timecode : 00:00:00:00
encoder : Lavc56.41.100 prores
Stream #0:1(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono,
s32 (24 bit), 1152 kb/s (default)
Metadata:
creation_time : 2016-10-11 12:30:25
handler_name : Apple Alias Data Handler
encoder : Lavc56.41.100 pcm_s24le
Stream mapping:
Stream #0:0 -> #0:0 (prores (native) -> prores (native))
Stream #0:1 -> #0:1 (pcm_s24le (native) -> pcm_s24le (native))
Press [q] to stop, [?] for help
frame= 2617 fps= 51 q=0.0 Lsize= 2132252kB time=00:01:49.04
bitrate=160190.2kbits/s
video:2116877kB audio:15334kB subtitle:0kB other streams:0kB global
headers:0kB muxing overhead: 0.001927%
_______________________________________________
ffmpeg-user mailing list
ffmpeg-***@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-reque
Steve Boyer
2016-10-11 22:00:50 UTC
Permalink
Post by Carles Vila
Hi, I'm trying to perform framerate conversion of a video, from 24fps to
25fps to be precise.
The source is mov, ProRes with multichannel audio at 48kHz.
It is mandatory for my application to preserve the integrity of all frames,
i.e. no frame-interpolation or duplication should occur.
In other words, just the playback speed should be increased from 24 to 25,
resulting in a video of slightly shorter duration.
I've been partially successful so far using the command
ffmpeg -r 25 -i <inputfile24fps.mov> -r 25 -c:v prores -profile:v 3 -c:a
pcm_s24le <output_25fps.mov>
This comand produces a good video, shorter than the original, but the
problem is with audio. As you can imagine, the audio drifts out of sync
because it has no knowledge of the video framerate conversion.
My solution now is to process the audio externally, in an audio editor. I
must apply a sample rate conversion, first forcing the sample rate metadata
to 50.000 Hz (48.000 *(25/24)) and then resampling at 48.000 Hz
This shortens the audio by the same amount as the video and can be merged
to it.
Is there any way to perform this audio processing within ffmpeg?
Thanks!
Have you tried experimenting with the audio filter "atempo"? I'm guessing
here, but try:

ffmpeg -i ...<your options here> -af atempo=0.96 <outfile>

(24/25 = 0.96)

~Steve
_______________________________________________
ffmpeg-user mailing list
ffmpeg-***@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-***@ffmpeg.org
Steve Boyer
2016-10-12 13:21:28 UTC
Permalink
Post by Steve Boyer
Have you tried experimenting with the audio filter "atempo"? I'm guessing
ffmpeg -i ...<your options here> -af atempo=0.96 <outfile>
(24/25 = 0.96)
Wow, I messed that one up completely. Incorporating Carl's suggestion as
well of -vf setpts, the filter chain should look something like:

ffmpeg -i <inputfile> -vf setpts=PTS*0.8 -af=atune=25/24 <codec options>
<output file>
or if -r works for you:
ffmpeg -r 25 -i <inputfile> -af=atune=25/24 <codec options> <output file>

Just a heads-up: on a test clip, looks like using -ss and -r before -i
causes frame-sync issues, so if you were wanting to skip forward into your
test clip, make sure to use -ss after -i <inputfile>.
Post by Steve Boyer
~Steve
_______________________________________________
ffmpeg-user mailing list
ffmpeg-***@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-***@ffmpeg.org with sub
Carles Vila
2016-10-13 09:41:52 UTC
Permalink
Post by Steve Boyer
Post by Steve Boyer
ffmpeg -i ...<your options here> -af atempo=0.96 <outfile>
(24/25 = 0.96)
Wow, I messed that one up completely. Incorporating Carl's suggestion as
ffmpeg -i <inputfile> -vf setpts=PTS*0.8 -af=atune=25/24 <codec options>
<output file>
ffmpeg -r 25 -i <inputfile> -af=atune=25/24 <codec options> <output file>
Hi, I have tested with the atempo filter and it certainly works! BTW I
think atune does not exist..:) Thanks for pointing me in the right
direction though.
A drawback for me is the fact that this filter performs pitch correction.
Anyone know what algorithm is being used?
Anyway, this introduces artifacts and phase issues in multichannel audio
which are unacceptable in my case. I have further investigated and found a
filter chain that suits my need: asetrate, followed by aresample. To be
precise i have used

ffmpeg -r 25 -i input_24fps.mov -af asetrate=50000,aresample=48000 -c:v
prores -profile:v 3 -c:a pcm_s24le output_25fps_resampledaudio.mov

where 50000=48000*(25/24)

My only remaining problem, is that my original mov has 6 audio streams but
my process only processes and outputs the first.
How can I apply the same filter to all audio streams?
Thank you!!
_______________________________________________
ffmpeg-user mailing list
ffmpeg-***@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-***@ffmpeg.org with sub
Carl Eugen Hoyos
2016-10-13 09:54:16 UTC
Permalink
Post by Carles Vila
ffmpeg -r 25 -i input_24fps.mov -af asetrate=50000,aresample=48000 -c:v
prores -profile:v 3 -c:a pcm_s24le output_25fps_resampledaudio.mov
where 50000=48000*(25/24)
My only remaining problem, is that my original mov has 6 audio streams but
my process only processes and outputs the first.
How can I apply the same filter to all audio streams?
You use -filter_complex instead of -vf and -af

-filter_complex
[0:0]setpts=PTS*0.8[v];[0:1]asetrate,aresample[a0];[0:2]asetrate,aresample[a1]
and then -map [v] -map [a0] -map [a1]
(untested)

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
ffmpeg-***@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-***@ffmpeg.org with subject
Carles Vila
2016-10-13 13:52:10 UTC
Permalink
Post by Carl Eugen Hoyos
Post by Carles Vila
How can I apply the same filter to all audio streams?
You use -filter_complex instead of -vf and -af
-filter_complex
[0:0]setpts=PTS*0.8[v];[0:1]asetrate,aresample[a0];[0:2]
asetrate,aresample[a1]
and then -map [v] -map [a0] -map [a1]
(untested)
After a couple of attempts, it works! But I keep using the -r 25 option
before -i. It works just fine for me.
_______________________________________________
ffmpeg-user mailing list
ffmpeg-***@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ff

Carl Eugen Hoyos
2016-10-12 11:44:10 UTC
Permalink
Post by Carles Vila
Hi, I'm trying to perform framerate conversion of a video, from 24fps to
25fps to be precise.
The source is mov, ProRes with multichannel audio at 48kHz.
It is mandatory for my application to preserve the integrity of all frames,
i.e. no frame-interpolation or duplication should occur.
Then use the setpts filter, the input option -r tends to be unreliable.
Although using setpts means you have to take care if audio and
video start at the same time.

Or to say it differently: setpts is recommended, if r works for you,
all the better!

Since you change the video length, you have to change audio
speed, I don't know if asetpts is an alternative to atempo.

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
ffmpeg-***@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-***@ffmpeg.org with subj
Loading...