Re: [FFmpeg-user] How can I get a duration and fps of any video that corresponds with the number of frames that can be read?
> AFAICT, no video tool has solved this without running the entire stream. You >might take one approach for fixed-rate containers/encodings and another for variable-rate. It might be worth adding that there is a frame-count field available in several container formats, but it is very rarely correctly set. I've worked extensively with AVIs that have frame-count fields which were neither zeroed, nor set to the actual frame count. So, don't trust 'em unless you trust the application that wrote the file, and even then that would be a "trusting the file" smell. P ___ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user To unsubscribe, visit link above, or email ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-user] How can I get a duration and fps of any video that corresponds with the number of frames that can be read?
On 8/5/2020 9:52 AM, Tom Burrows via ffmpeg-user wrote: I need to get the duration of any video file such that when multiplied with the media's fps value (in this case, either ’tbr’ or ‘fps'), it equals the number of frames in the video. That works until you find a variable frame-rate video. I have found that to get a truly accurate duration or frame-count, you have to effectively render the entire file, even if to /dev/null. It does take (much) longer, but it's not really a re-encode, just a copy. A prime example of this is an mp2 pulled out of a dvd vob- I've seen a lot of cases where the metadata info is wildly wrong* or that parts of the video change between 24 fps and 29.97, there's also the 3:2 pulldown flag *duration 00:46:13 on a 90 minute movie? I think not. AFAICT, no video tool has solved this without running the entire stream. You might take one approach for fixed-rate containers/encodings and another for variable-rate. Later, z! ___ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user To unsubscribe, visit link above, or email ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-user] How can I get a duration and fps of any video that corresponds with the number of frames that can be read?
A long time ago I hit this and as far as I was then able to tell, there is not a lightweight way to get the precise number of frames in a video file. I seem to recall (don't ask me how) there was a way to effectively have it "play" the file, to parse the container, without actually doing the work of decoding the frames. That's less hard work than literally decoding it all. It's still not a very cheap way to count frames, but it was the best solution I could find. Someone here may be able to advise. P On Wednesday, 5 August 2020, 18:01:27 BST, Tom Burrows via ffmpeg-user wrote: I'm a developer of the Python MoviePy package and I'm trying to rework how we import file information to be more robust. I need to get the duration of any video file such that when multiplied with the media's fps value (in this case, either ’tbr’ or ‘fps'), it equals the number of frames in the video. I've found 3 solutions: (1) ffmpeg -i broken_video.mp4 (2) ffmpeg -i broken_video.mp4 -f null - (3) ffmpeg -i broken_video.mp4 -codec copy -f null - (Full outputs at the end) FFmpeg reports that the video has 29.90 fps, 30 tbr, and contains 305 frames. They all list Duration: 00:00:10.26 near the top. I believe that this is derived from the metadata and has proved to be unreliable, so I'd rather avoid using this. In this case, 10.26x30=307.8 (2) has time=00:00:10.21 near the bottom. 10.21x30=306.3. Also, this one is a lot slower since it is re-encoding the entire file. (3) has time=00:00:10.19 10.19x30=305.7. This is the closest to 305, although it still rounds incorrectly. I've also considered simply taking the fps and the number of frames and generating the duration from this (in this case, 30x305= 10.16667), but I’m assuming that sometimes the fps is wrong? (occasionally the tbr is something crazy like 10k and that would surely create an incorrect duration. Maybe this behaviour wouldn’t happen with ‘fps’?). Is there a better solution to this problem? — $ ffmpeg -i broken_video.mp4 ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers built with Apple clang version 11.0.0 (clang-1100.0.33.17) configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.2_2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack 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 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 5.100 / 5. 5.100 libswresample 3. 5.100 / 3. 5.100 libpostproc 55. 5.100 / 55. 5.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'broken_video.mp4': Metadata: minor_version : 512 major_brand : isom compatible_brands: isomiso2avc1mp41 information : {"com.bytedance.info": "{}"} comment : vid:v0200f97brb4glubn5v3g13q5db0 encoder : Lavf58.20.100 Duration: 00:00:10.26, start: 0.00, bitrate: 743 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/smpte170m), 576x1024 [SAR 1:1 DAR 9:16], 608 kb/s, 29.90 fps, 30 tbr, 15360 tbn, 60 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default) Metadata: handler_name : SoundHandler At least one output file must be specified $ ffmpeg -i broken_video.mp4 -f null - ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers built with Apple clang version 11.0.0 (clang-1100.0.33.17) configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.2_2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --ena
[FFmpeg-user] How can I get a duration and fps of any video that corresponds with the number of frames that can be read?
I'm a developer of the Python MoviePy package and I'm trying to rework how we import file information to be more robust. I need to get the duration of any video file such that when multiplied with the media's fps value (in this case, either ’tbr’ or ‘fps'), it equals the number of frames in the video. I've found 3 solutions: (1) ffmpeg -i broken_video.mp4 (2) ffmpeg -i broken_video.mp4 -f null - (3) ffmpeg -i broken_video.mp4 -codec copy -f null - (Full outputs at the end) FFmpeg reports that the video has 29.90 fps, 30 tbr, and contains 305 frames. They all list Duration: 00:00:10.26 near the top. I believe that this is derived from the metadata and has proved to be unreliable, so I'd rather avoid using this. In this case, 10.26x30=307.8 (2) has time=00:00:10.21 near the bottom. 10.21x30=306.3. Also, this one is a lot slower since it is re-encoding the entire file. (3) has time=00:00:10.19 10.19x30=305.7. This is the closest to 305, although it still rounds incorrectly. I've also considered simply taking the fps and the number of frames and generating the duration from this (in this case, 30x305= 10.16667), but I’m assuming that sometimes the fps is wrong? (occasionally the tbr is something crazy like 10k and that would surely create an incorrect duration. Maybe this behaviour wouldn’t happen with ‘fps’?). Is there a better solution to this problem? — $ ffmpeg -i broken_video.mp4 ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers built with Apple clang version 11.0.0 (clang-1100.0.33.17) configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.2_2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack libavutil 56. 31.100 / 56. 31.100 libavcodec 58. 54.100 / 58. 54.100 libavformat58. 29.100 / 58. 29.100 libavdevice58. 8.100 / 58. 8.100 libavfilter 7. 57.100 / 7. 57.100 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 5.100 / 5. 5.100 libswresample 3. 5.100 / 3. 5.100 libpostproc55. 5.100 / 55. 5.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'broken_video.mp4': Metadata: minor_version : 512 major_brand : isom compatible_brands: isomiso2avc1mp41 information : {"com.bytedance.info": "{}"} comment : vid:v0200f97brb4glubn5v3g13q5db0 encoder : Lavf58.20.100 Duration: 00:00:10.26, start: 0.00, bitrate: 743 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/smpte170m), 576x1024 [SAR 1:1 DAR 9:16], 608 kb/s, 29.90 fps, 30 tbr, 15360 tbn, 60 tbc (default) Metadata: handler_name: VideoHandler Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default) Metadata: handler_name: SoundHandler At least one output file must be specified $ ffmpeg -i broken_video.mp4 -f null - ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers built with Apple clang version 11.0.0 (clang-1100.0.33.17) configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.2_2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack libavutil 56. 31.100 / 56. 31.100 libavcodec 58. 54.100 / 58. 54.100 libavformat58. 29.100 / 58. 29.100 libavdevice58. 8.100 / 58. 8.100 libavfilter 7. 57.100 / 7. 57.100 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 5.100 / 5. 5.100 libswresample 3. 5.100 / 3. 5.100 libpostproc55. 5.100 / 55. 5.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'broken_video.mp4': Metadata: minor_version : 512 major_brand : isom compatible_brands: is