FFmpeg inaccurate outputs [duplicate] - audio

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
ffmpeg: videos before and after conversion aren't the same length
Recently, I've been trying to use FFmpeg for an application which requires a VERY accurate manipulation when it comes to the time parameter (milliseconds resolution). Unfortunately, I was surprised to find out that FFmpeg's manipulation functionalities return some inaccurate results.
Here is the output of 'ffmpeg':
ffmpeg version 0.11.1 Copyright (c) 2000-2012 the FFmpeg developers
built on Jul 25 2012 19:55:05 with gcc 4.2.1 (Apple Inc. build 5664)
configuration: --enable-gpl --enable-shared --enable-pthreads --enable-libx264 --enable-libmp3lame
libavutil 51. 54.100 / 51. 54.100
libavcodec 54. 23.100 / 54. 23.100
libavformat 54. 6.100 / 54. 6.100
libavdevice 54. 0.100 / 54. 0.100
libavfilter 2. 77.100 / 2. 77.100
libswscale 2. 1.100 / 2. 1.100
libswresample 0. 15.100 / 0. 15.100
libpostproc 52. 0.100 / 52. 0.100
Now, let's assume I want to rip the audio track of 'foo.mov'. Here is the relevant output of 'ffmpeg -i foo.mov':
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'foo.mov':
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
creation_time : 2012-07-24 23:16:08
Duration: 00:00:40.38, start: 0.000000, bitrate: 805 kb/s
Stream #0:0(und): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 480x360, 733 kb/s, 24.46 fps, 29.97 tbr, 600 tbn, 1200 tbc
Metadata:
rotate : 90
creation_time : 2012-07-24 23:16:08
handler_name : Core Media Data Handler
Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, s16, 63 kb/s
Metadata:
creation_time : 2012-07-24 23:16:08
handler_name : Core Media Data Handler
As you probably noticed, the video file duration is 00:00:40.38. Using the following command, I ripped it's audio track:
'ffmpeg -i foo.mov foo.wav'
Output:
Output #0, wav, to 'foo.wav':
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
creation_time : 2012-07-24 23:16:08
encoder : Lavf54.6.100
Stream #0:0(und): Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, mono, s16, 705 kb/s
Metadata:
creation_time : 2012-07-24 23:16:08
handler_name : Core Media Data Handler
Stream mapping:
Stream #0:1 -> #0:0 (aac -> pcm_s16le)
Press [q] to stop, [?] for help
size=3482kB time=00:00:40.42 bitrate= 705.6kbits/s
video:0kB audio:3482kB global headers:0kB muxing overhead 0.001290%
As you can see, the output file is longer than the file in the input.
Another example is audio (and video) file trimming:
Let's assume I would like to use ffmpeg for audio file trimming. I used the next command:
'ffmpeg -t 00:00:10.000 -i foo.wav trimmed_foo.wav -ss 00:00:25.000'
Output:
[wav # 0x10180e800] max_analyze_duration 5000000 reached at 5015510
Guessed Channel Layout for Input Stream #0.0 : mono
Input #0, wav, from 'foo.wav':
Duration: 00:00:40.42, bitrate: 705 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, mono, s16, 705 kb/s
Output #0, wav, to 'trimmed_foo.wav':
Metadata:
encoder : Lavf54.6.100
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, mono, s16, 705 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (pcm_s16le -> pcm_s16le)
Press [q] to stop, [?] for help
size=864kB time=00:00:10.03 bitrate= 705.6kbits/s
video:0kB audio:864kB global headers:0kB muxing overhead 0.005199%
Again, the output file is 30 milliseconds longer than I expected.
I tried, for a long time, to research the issue without any success. When I use audacity for the same functionality, it does it very accurately!
Does anyone have any idea how to solve this problem?

TL; DR: FFmpeg and your iOS device are the wrong tools for your needs.
There are a host of problems to cover, so in no particular order:
Neither FFmpeg or the underlying codecs that you're working with are designed for the sort of time resolution you want. 40ms is 1 frame at 25fps, which just isn't much in the context of most video and audio files. Hyperaccurate timing isn't a design feature of common audio codecs, like your source AAC data, and FFmpeg follows suit.
Don't do any transcoding! If you want to change the data as little as possible... don't change it. You can use ffmpeg -i in.mov -c:a copy out.m4a to extract the audio stream exactly instead of transcoding it to wav format.
Use FFprobe instead of FFmpeg to get file information. FFmpeg just gives some cursory information about input and output files because its default logging is overly verbose. FFprobe is usually bundled with FFmpeg and is specifically designed to extract information in a convenient form. Use ffprobe -show_streams -show_format in.mov to get information.
Increase your -analyzeduration! You might've noticed the note about max_analyze_duration reached in your output. From the docs that's how many microseconds are going to actually be read of the file before FFmpeg estimates the total length. Again, for most purposes knowing the length of the file to microsecond accuracy isn't feasible or desirable and it is expensive. If you want hyperaccuracy, make sure that that parameter is set much higher, probably longer than your actual input.
Be a bit more careful with your option placement. This is fairly minor, but I thought that I should bring it up in case you're unaware. Many of FFmpeg's options behave differently depending on the order they're given with respect to input and output. Notably -ss that you're using. You have it after the input, which is where you want it, but you also have the output-only option -t at the beginning which is... weird. The more natural way to order that command would be:
ffmpeg -i foo.wav -ss 00:00:25.000 -t 00:00:10.000 trimmed_foo.wav
All the timing commands accept input in seconds (including fractional seconds), so you don't have to prepend everything with 00:00:.
Distinguish container length and actual stream length. I don't use Audacity, but I wouldn't be surprised if it showed extreme accuracy because it was lying to you about what it was doing. Actually trimming audio or video data with millisecond accuracy would require not merely choosing which frames from the input are included in the output (which is accurate to 40ms at 25fps!) but changing frame data to insert silence at the end. Far easier would be to just trim based on frame inclusion, then put the hyper-accurate length in the container file metadata. Some playback software might actually cut off based on that number, but again, most AV software just isn't designed for that level of accuracy. I would be curious to see what FFmpeg shows as the length of a file trimmed by Audacity.
That's all that springs to mind now, but I'm happy to give more feedback once you've had a chance to incorporate some of the above. My guess would be that this sort of accuracy is required for research pruposes, in which case, happy researching!

Related

How do you use FFMPEG to transcode h264_qsv from Apple PRORES Quicktime?

I am trying to transcode an Apple Prores 444 to H.264 using qsv without success.
If I use this command line:
ffmpeg -i 10minute_Pipeline_Test.mov -c:v h264_qsv -c:a aac -pix_fmt qsv chris.mp4
I get:
ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)
configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-nonfree --enable-libmfx
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Guessed Channel Layout for Input Stream #0.2 : mono
Guessed Channel Layout for Input Stream #0.3 : mono
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '10minute_Pipeline_Test.mov':
Metadata:
major_brand : qt
minor_version : 537134592
compatible_brands: qt
creation_time : 2020-12-19T12:43:38.000000Z
com.apple.quicktime.author:
com.apple.quicktime.comment:
com.apple.quicktime.copyright:
com.apple.quicktime.description:
com.apple.quicktime.director:
com.apple.quicktime.genre:
com.apple.quicktime.information:
com.apple.quicktime.keywords:
com.apple.quicktime.producer:
com.apple.quicktime.displayname:
timecode : 12:43:37;28
Duration: 00:10:06.72, start: 0.000000, bitrate: 167429 kb/s
Stream #0:0(eng): Data: none (tmcd / 0x64636D74)
Metadata:
creation_time : 1970-01-04T00:49:14.000000Z
timecode : 12:43:37;28
Stream #0:1(eng): Video: prores (Standard) (apcn / 0x6E637061), yuv422p10le(tv, GBR, progressive), 1280x720, 164985 kb/s, SAR 1:1 DAR 16:9, 59.94 fps, 59.94 tbr, 60k tbn, 60k tbc (default)
Metadata:
creation_time : 1970-01-01T00:00:04.000000Z
Stream #0:2(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono, s32 (24 bit), 1152 kb/s (default)
Stream #0:3(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono, s32 (24 bit), 1152 kb/s (default)
Metadata:
creation_time : 2003-10-05T11:26:56.000000Z
File 'chris.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
Stream #0:1 -> #0:0 (prores (native) -> h264 (h264_qsv))
Stream #0:2 -> #0:1 (pcm_s24le (native) -> aac (native))
Press [q] to stop, [?] for help
[h264_qsv # 0x56265b81a800] Selected ratecontrol mode is unsupported
[h264_qsv # 0x56265b81a800] Low power mode is unsupported
[h264_qsv # 0x56265b81a800] Current frame rate is unsupported
[h264_qsv # 0x56265b81a800] Current picture structure is unsupported
[h264_qsv # 0x56265b81a800] Current resolution is unsupported
[h264_qsv # 0x56265b81a800] Current pixel format is unsupported
[h264_qsv # 0x56265b81a800] some encoding parameters are not supported by the QSV runtime. Please double check the input parameters.
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
user#NUC:~$ ffmpeg -i 10minute_Pipeline_Test.mov -c:v h264_qsv -c:a aac -pix_fmt qsv chris.mp4
ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)
configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-nonfree --enable-libmfx
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Guessed Channel Layout for Input Stream #0.2 : mono
Guessed Channel Layout for Input Stream #0.3 : mono
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '10minute_Pipeline_Test.mov':
Metadata:
major_brand : qt
minor_version : 537134592
compatible_brands: qt
creation_time : 2020-12-19T12:43:38.000000Z
com.apple.quicktime.author:
com.apple.quicktime.comment:
com.apple.quicktime.copyright:
com.apple.quicktime.description:
com.apple.quicktime.director:
com.apple.quicktime.genre:
com.apple.quicktime.information:
com.apple.quicktime.keywords:
com.apple.quicktime.producer:
com.apple.quicktime.displayname:
timecode : 12:43:37;28
Duration: 00:10:06.72, start: 0.000000, bitrate: 167429 kb/s
Stream #0:0(eng): Data: none (tmcd / 0x64636D74)
Metadata:
creation_time : 1970-01-04T00:49:14.000000Z
timecode : 12:43:37;28
Stream #0:1(eng): Video: prores (Standard) (apcn / 0x6E637061), yuv422p10le(tv, GBR, progressive), 1280x720, 164985 kb/s, SAR 1:1 DAR 16:9, 59.94 fps, 59.94 tbr, 60k tbn, 60k tbc (default)
Metadata:
creation_time : 1970-01-01T00:00:04.000000Z
Stream #0:2(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono, s32 (24 bit), 1152 kb/s (default)
Stream #0:3(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono, s32 (24 bit), 1152 kb/s (default)
Metadata:
creation_time : 2003-10-05T11:26:56.000000Z
File 'chris.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
Stream #0:1 -> #0:0 (prores (native) -> h264 (h264_qsv))
Stream #0:2 -> #0:1 (pcm_s24le (native) -> aac (native))
Press [q] to stop, [?] for help
Impossible to convert between the formats supported by the filter 'Parsed_null_0' and the filter 'auto_scaler_0'
Error reinitializing filters!
Failed to inject frame into filter network: Function not implemented
Error while processing the decoded data for stream #0:1
Conversion failed!
If I use:
ffmpeg -i 10minute_Pipeline_Test.mov -c:v h264_qsv -c:a aac chris.mp4
I get:
ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)
configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-nonfree --enable-libmfx
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Guessed Channel Layout for Input Stream #0.2 : mono
Guessed Channel Layout for Input Stream #0.3 : mono
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '10minute_Pipeline_Test.mov':
Metadata:
major_brand : qt
minor_version : 537134592
compatible_brands: qt
creation_time : 2020-12-19T12:43:38.000000Z
com.apple.quicktime.author:
com.apple.quicktime.comment:
com.apple.quicktime.copyright:
com.apple.quicktime.description:
com.apple.quicktime.director:
com.apple.quicktime.genre:
com.apple.quicktime.information:
com.apple.quicktime.keywords:
com.apple.quicktime.producer:
com.apple.quicktime.displayname:
timecode : 12:43:37;28
Duration: 00:10:06.72, start: 0.000000, bitrate: 167429 kb/s
Stream #0:0(eng): Data: none (tmcd / 0x64636D74)
Metadata:
creation_time : 1970-01-04T00:49:14.000000Z
timecode : 12:43:37;28
Stream #0:1(eng): Video: prores (Standard) (apcn / 0x6E637061), yuv422p10le(tv, GBR, progressive), 1280x720, 164985 kb/s, SAR 1:1 DAR 16:9, 59.94 fps, 59.94 tbr, 60k tbn, 60k tbc (default)
Metadata:
creation_time : 1970-01-01T00:00:04.000000Z
Stream #0:2(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono, s32 (24 bit), 1152 kb/s (default)
Stream #0:3(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono, s32 (24 bit), 1152 kb/s (default)
Metadata:
creation_time : 2003-10-05T11:26:56.000000Z
File 'chris.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
Stream #0:1 -> #0:0 (prores (native) -> h264 (h264_qsv))
Stream #0:2 -> #0:1 (pcm_s24le (native) -> aac (native))
Press [q] to stop, [?] for help
Impossible to convert between the formats supported by the filter 'Parsed_null_0' and the filter 'auto_scaler_0'
Error reinitializing filters!
Failed to inject frame into filter network: Function not implemented
Error while processing the decoded data for stream #0:1
Conversion failed!
user#NUC:~$ ffmpeg -i 10minute_Pipeline_Test.mov -c:v h264_qsv -c:a aac chris.mp4
ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)
configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-nonfree --enable-libmfx
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Guessed Channel Layout for Input Stream #0.2 : mono
Guessed Channel Layout for Input Stream #0.3 : mono
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '10minute_Pipeline_Test.mov':
Metadata:
major_brand : qt
minor_version : 537134592
compatible_brands: qt
creation_time : 2020-12-19T12:43:38.000000Z
com.apple.quicktime.author:
com.apple.quicktime.comment:
com.apple.quicktime.copyright:
com.apple.quicktime.description:
com.apple.quicktime.director:
com.apple.quicktime.genre:
com.apple.quicktime.information:
com.apple.quicktime.keywords:
com.apple.quicktime.producer:
com.apple.quicktime.displayname:
timecode : 12:43:37;28
Duration: 00:10:06.72, start: 0.000000, bitrate: 167429 kb/s
Stream #0:0(eng): Data: none (tmcd / 0x64636D74)
Metadata:
creation_time : 1970-01-04T00:49:14.000000Z
timecode : 12:43:37;28
Stream #0:1(eng): Video: prores (Standard) (apcn / 0x6E637061), yuv422p10le(tv, GBR, progressive), 1280x720, 164985 kb/s, SAR 1:1 DAR 16:9, 59.94 fps, 59.94 tbr, 60k tbn, 60k tbc (default)
Metadata:
creation_time : 1970-01-01T00:00:04.000000Z
Stream #0:2(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono, s32 (24 bit), 1152 kb/s (default)
Stream #0:3(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono, s32 (24 bit), 1152 kb/s (default)
Metadata:
creation_time : 2003-10-05T11:26:56.000000Z
File 'chris.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
Stream #0:1 -> #0:0 (prores (native) -> h264 (h264_qsv))
Stream #0:2 -> #0:1 (pcm_s24le (native) -> aac (native))
Press [q] to stop, [?] for help
[h264_qsv # 0x55b3bb6e8800] Selected ratecontrol mode is unsupported
[h264_qsv # 0x55b3bb6e8800] Low power mode is unsupported
[h264_qsv # 0x55b3bb6e8800] Current frame rate is unsupported
[h264_qsv # 0x55b3bb6e8800] Current picture structure is unsupported
[h264_qsv # 0x55b3bb6e8800] Current resolution is unsupported
[h264_qsv # 0x55b3bb6e8800] Current pixel format is unsupported
[h264_qsv # 0x55b3bb6e8800] some encoding parameters are not supported by the QSV runtime. Please double check the input parameters.
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
I cannot get ANYTHING to work. I can transcode other h264 files without issue. I cannot seem to transcode this prores file.
Here is a link to the source file if anyone can help I would REALLY appreciate it...
https://www.dropbox.com/s/ejrfzad20yzaifm/10minute_Pipeline_Test.mov?dl=1
I use H264_QSV daily, and I find you have to declare the QSV device as being available.
Try this:
ffmpeg -err_detect ignore_err -hide_banner -loglevel verbose -init_hw_device qsv:qsv,child_device_type=qsv ^ -hwaccel qsv -hwaccel_output_format qsv -i "input.mov" -q:v 30 -preset slow -c:a aac output.mp4
There are many more options that can be added to improve efficiency, change the quality (the -q:v setting), etc.
I've found that QSV speeds things up so much that you can use a -preset of slow or very slow to get more compression for a given quality setting without significantly increasing the time it takes to convert the file.
I may not have done the copy as well as I should have.
This is a more complete copy of how I use ffmpeg.
ffmpeg -err_detect ignore_err -hide_banner -loglevel verbose -stats -benchmark -init_hw_device qsv:qsv,child_device_type=qsv ^
-hwaccel qsv -hwaccel_output_format qsv ^
-i "input file" ^
-c:a aac -q:a 1.9 -strict normal -sws_flags lanczos ^
-vf "vpp_qsv=cw=704:ch=480:cx=11:cy=0:w=640:h=480" ^
-async_depth 128 -q:v 28 -c:v h264_qsv -preset veryslow (a bunch of optimization options on how I want the compression to be done go in here, which can be discussed separately) -movflags +faststart "output file.mp4"
This is on Windows so the carat "^" is the command line continuation character.
-err_detect suppresses some of the more useless messages. -hide_banner suppresses things that I normally don't need to see at all.
-loglevel is usually set to "info" or "quiet", but if you want to know exactly which codecs are being used, set it to "verbose" as it is here.
This is the simple answer to the original question, "Am I using the QSV codec?".
-strict normal is optional, but I found some applications didn't do well with some of the newer optimizations. It does not appear to increase file size to any significant extent, and I don't run into problems running videos on old equipment.
I put the audio processing first as it seems to work better that way.
I let the codec choose the bit rate by setting the quality, as with the video (see below).
I have also included an example of the vpp_qsv video processing filter, as I find it speeds up many operations. It can, of course, be left out if you don't need it. I put it before the compression codec: ffmpeg will process them in the proper order, but I find it's easier to keep track of what's going on if I put the commands in about the same order as they will eventually be processed. When I put the commands in this order and "verbose" is on, ffmpeg reports that the output of the vpp_qsv filter remains in video memory as the input to the h264_qsv codec. This speeds things up in my tests: or, at least, it reduces the CPU load so other programs can run at the same time.
-async_depth is optional, increases the number of frames that are read before compression is done; I find this also usually makes things go a bit faster. -q:v is the compression quality setting: I've found 28 to 30 gives me good results for watching videos on a reasonably large TV, but you will have to make tests for yourself to see what setting is right for you. Doing this is much, much better than guessing what bitrate you need, the codec can do better optimizations, and so on. You will, in most cases, get variable bit rate compression, and sometimes variable frame rates. This improves compression for parts of the video that don't have much going on, while still providing higher bit rates when needed. You may be surprised at how low a bit rate can be produced this way and still have a good quality video.
I put -movflags +faststart in ALL of my MP4 videos. This moves a copy of the MOOV atom from the end of the video to the beginning. This does at least two things. First, for many players, the video will start playing faster as the information the player needs about the video is read immediately. Second, if an MP4 file ever gets truncated and the MOOV atom is missing, you will not be able to play the file at all. There are programs that pretend to be able to recover the missing information, but I have yet to see one actually work. But if the MOOV atom is also included at the beginning of the video, you will at least be able to start processing the video, and should at least get to the point where the file is damaged. It's cheap insurance, and only takes a moment or two. (This won't work if your output is a live stream, the video has to be "finished" before the atom is created.)
-stats and -benchmark are optional, I like to see how fast processing is going and be able to compare it to other times I process videos to see if any changes I make to the options are helping or not.
If there is an interest in the various vpp_qsv filter options, or in what other compression settings I use, or what settings will allow videos to work with Roku Media Player, let me know which topic I should post that in.

Extract audio with ffmpeg, linux

I'm trying to extract audio tracks from some Avi videos and save them to their own files, ideally without re-encoding.
I've had a look through here https://www.ffmpeg.org/ffmpeg.html#Audio-Options and here ffmpeg to extract audio from video though I'm getting errors regardless of the approach I try.
My latest command string is:
ffmpeg -i /home/d/Pictures/Test/input-video.AVI -map 0:a -vn -acodec copy /home/d/Pictures/Test/output-audio.m4a
The key part of the output is:
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, avi, from '/home/d/Pictures/Test/input-video.AVI':
Duration: 00:00:05.94, start: 0.000000, bitrate: 18131 kb/s
Stream #0:0: Video: mjpeg (MJPG / 0x47504A4D), yuvj422p(pc, bt470bg/unknown/unknown), 1280x720, 17995 kb/s, 30.28 fps, 30.28 tbr, 30.28 tbn, 30.28 tbc
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 11025 Hz, 1 channels, s16, 176 kb/s
File '/home/d/Pictures/Test/output-audio.m4a' already exists. Overwrite ? [y/N] y
[ipod # 0x1d89520] Codec for stream 0 does not use global headers but container format requires global headers
[ipod # 0x1d89520] Could not find tag for codec pcm_s16le in stream #0, codec not currently supported in container
Output #0, ipod, to '/home/d/Pictures/Test/output-audio.m4a':
Metadata:
encoder : Lavf56.40.101
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 11025 Hz, mono, 176 kb/s
Stream mapping:
Stream #0:1 -> #0:0 (copy)
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
I'm believe I have got the right audio stream number from this output and thus am assuming the "-map 0:a" part isn't the problem.
I'm running on Linux Mint 18.1
MP4 family of formats don't store PCM audio, so you either have to re-encode or save to another format, like Matroska.
ffmpeg -i video.AVI -map 0:a -vn -acodec copy audio.mka

Not able to change the program number for the video

I have been trying to change the program number of a particular .ts file using FFmpeg without any success. I saw the documentation and it mentions to use the -program option. But, I am not able to add the streams as I desire. Here's the program information for the stream that I possess currently:
Input #0, mpegts, from 'output_2_without_pgm_num.ts':
Duration: 00:01:49.92, start: 1.400000, bitrate: 1816 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv, progressive), 720x576 [SAR 64:45 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
Stream #0:1[0x101](ger): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 384 kb/s (clean effects)
Stream #0:2[0x102](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, fltp, 384 kb/s (clean effects)
Stream #0:3[0x103](ger): Subtitle: dvb_teletext ([6][0][0][0] / 0x0006)
Now, I want to change the program number from 1 to 22. Any idea how I could do that? I have tried using -program option, but I can't add streams 2 and 3 to the newly created .ts file.
Thanks in advance!
There are two steps involved here. Telling ffmpeg which streams to include in the output using the -map option, and setting the program metadata, using the -program option.
ffmpeg -i in.ts -map 0 -c copy -program program_num=22:st=0:st=1:st=2:st=3 out.ts
-map 0 tells ffmpeg to include all streams from the first input.
The st values tell ffmpeg which output stream indices should be included in the program.

Encoder (codec none) not found for output stream #0:1 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
Hi i built ffmpeg executable on Redhat5. I want to mix two Audio using the command multiple
"ffmpeg -i INPUT1 -i INPUT2 -i INPUT3 -filter_complex amix=inputs=3:duration=first:dropout_transition=3 OUTPUT.mp3".
I enabled libflamemp3 library without any error.
[root#localhost ~]# ffmpeg -i /root/media/Katlalli.mp3 -i /root/media/Katlalli.mp3 -filter_complex amix=inputs=2:duration=first:dropout_transition=2 /root/media/OUTPutnew123.mp3
ffmpeg version 2.1 Copyright (c) 2000-2013 the FFmpeg developers
built on Nov 14 2013 03:17:10 with gcc 4.1.2 (GCC) 20080704 (Red Hat 4.1.2-46)
configuration: --enable-libmp3lame
libavutil 52. 48.100 / 52. 48.100
libavcodec 55. 39.100 / 55. 39.100
libavformat 55. 19.104 / 55. 19.104
libavdevice 55. 5.100 / 55. 5.100
libavfilter 3. 90.100 / 3. 90.100
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
[mp3 # 0x193ef240] Estimating duration from bitrate, this may be inaccurate
Input #0, mp3, from '/root/media/Katlalli.mp3':
Metadata:
artist : Yograj Bhat
title : Katlalli Karadige
track : 3
album : Paramathma
album_artist : Puneet Rajkumar
genre : Kannada
composer : V.Harikrishna
date : 2011
Duration: 00:04:41.46, start: 0.000000, bitrate: 191 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16p, 192 kb/s
Stream #0:1: Video: mjpeg, yuvj420p(pc), 200x200 [SAR 96:96 DAR 1:1], 90k tbr, 90k tbn, 90k tbc
Metadata:
title : thumbnail
comment : Cover (front)
[mp3 # 0x194090a0] Estimating duration from bitrate, this may be inaccurate
Input #1, mp3, from '/root/media/Katlalli.mp3':
Metadata:
artist : Yograj Bhat
title : Katlalli Karadige
track : 3
album : Paramathma
album_artist : Puneet Rajkumar
genre : Kannada
composer : V.Harikrishna
date : 2011
Duration: 00:04:41.46, start: 0.000000, bitrate: 191 kb/s
Stream #1:0: Audio: mp3, 44100 Hz, stereo, s16p, 192 kb/s
Stream #1:1: Video: mjpeg, yuvj420p(pc), 200x200 [SAR 96:96 DAR 1:1], 90k tbr, 90k tbn, 90k tbc
Metadata:
title : thumbnail
comment : Cover (front)
File '/root/media/OUTPutnew123.mp3' already exists. Overwrite ? [y/N] y
Output #0, mp3, to '/root/media/OUTPutnew123.mp3':
Metadata:
artist : Yograj Bhat
title : Katlalli Karadige
track : 3
album : Paramathma
album_artist : Puneet Rajkumar
genre : Kannada
composer : V.Harikrishna
date : 2011
Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp (default)
Stream #0:1: Video: none, q=2-31, 128 kb/s, 90k tbn
Metadata:
title : thumbnail
comment : Cover (front)
Stream mapping:
Stream #0:0 (mp3) -> amix:input0
Stream #1:0 (mp3) -> amix:input1
amix -> Stream #0:0 (libmp3lame)
Stream #0:1 -> #0:1 (mjpeg -> ?)
Encoder (codec none) not found for output stream #0:1
But when i try to combine two mp3 audio,
"ffmpeg -i INPUT1 -i INPUT2 -i INPUT3 -filter_complex amix=inputs=3:duration=first:dropout_transition=3 OUTPUT.mp3".
I am getting error like
"Encoder (codec none) not found for output stream #0:1"
so please help me how to link or install "libmp3flame" on Redhat5.
zlib
I believe ffmpeg is trying to decode a PNG input video stream (the album art) and encode the output video stream to PNG output, but I assume you built ffmpeg without zlib support which is required for PNG encoding and decoding.
zlib is automatically detected if available, so you needed to install the zlib headers prior to ffmpeg compilation (zlib-devel package for Red Hat 'n friends).
omit video
Alternatively you can keep your build and tell ffmpeg to ignore any video with the -vn output option.
use mjpeg
If you want to keep your build and also keep the album art then add -codec:v mjpeg as an output option. See stream selection to see which of the two inputs ffmpeg will choose.
use -codec:v copy
You can also stream copy the video with -codec:v copy. This is probably preferable over re-encoding with -codec:v mjpeg. See stream selection to see which of the two inputs ffmpeg will choose. If you add -map 0 -map 1 then both video streams will be included.
also see
Compile FFmpeg on CentOS

ffmpeg segments only the first part of my audio file

I'm implementing a http live streaming server to send audio file to iOS devices.
No problem with Apple's tools, mediafilesegmenter, my files are valid and it works fine.
I'm trying now to segment the same file using ffmpeg. I've downloaded the last stable version which is the 0.10.2 for now.
Here is how I try to segment my mp3 file:
./ffmpeg -re -i input.mp3 -f segment -segment_time 10 -segment_list outputList.m3u8 -acodec libmp3lame -map 0 output%03d.mp3
It starts the mapping like expected but finish with only one .mp3 file.
Did I miss something in the process?
Thanks in advance.
edit
Ok here is my latest command line:
ffmpeg -i input.mp3 -c:a libmp3lame -b:a 128k -map 0:0 -f segment -segment_time 10 -segment_list outputlist.m3u8 -segment_format mp3 'output%03d.mp3'
It still gives me only one file but the file is the hole song, not only one part.
Here is the output of ffmpeg:
ffmpeg version 0.10.2 Copyright (c) 2000-2012 the FFmpeg developers
built on Apr 20 2012 07:08:29 with gcc 4.5.2
configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libmp3lame
libavutil 51. 35.100 / 51. 35.100
libavcodec 53. 61.100 / 53. 61.100
libavformat 53. 32.100 /
53. 32.100
libavdevice 53. 4.100 / 53. 4.100
libavfilter 2. 61.100 / 2. 61.100
libswscale 2. 1.100 / 2. 1.100
libswresample 0. 6.100 / 0. 6.100
libpostproc 52. 0.100 / 52. 0.100
[mp3 # 0x8e4f120] max_analyze_duration 5000000 reached at 5015510
Input #0, mp3, from 'BeachHouse-Myth.mp3':
Metadata:
title : Myth
artist : Beach House
track : /
album : Bloom
disc : /
genre : Alternative
TSRC : USSUB1296501
Duration: 00:04:18.69, start: 0.000000, bitrate: 320 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16, 320 kb/s Output #0, segment, to 'stream%03d.mp3': Metadata:
title : Myth
artist : Beach House
track : /
album : Bloom
disc : /
genre : Alternative
TSRC : USSUB1296501
encoder : Lavf53.32.100
Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16, 128 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (mp3 -> libmp3lame)
Press [q] to stop, [?] for help
Truncating packet of size 1024 to 105ate= 0.0kbits/s
Truncating packet of size 1024 to 1
size= 0kB time=00:04:18.71 bitrate= 0.0kbits/s video:0kB audio:4042kB global headers:0kB muxing overhead -100.000000%
Audio only might be a bug. I contacted the FFMPEG player bug list, and a bug is filed: http://ffmpeg.org/trac/ffmpeg/ticket/1290

Resources