Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrections to video duration detection #1222

Merged
merged 13 commits into from
Oct 3, 2020

Conversation

tburrows13
Copy link
Collaborator

@tburrows13 tburrows13 commented Jun 8, 2020

Updates #1063. This PR essentially does what #1063 was supposed to do.

The linked StackOverflow post that inspired #1063 was correct, but it was only addressing audio files. In order for this to apply to audio and video, I've removed the -acodec (audio codec) argument and replaced it with the -codec argument which applies to all streams (audio and video). Without this change, FFmpeg decodes every video frame which takes a long time.

Secondly, here is the output from FFmpeg with the 2 different commands:

ffmpeg -i big_buck_bunny_0_30.webm
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, matroska,webm, from 'big_buck_bunny_0_30.webm':
  Metadata:
    encoder         : Lavf57.25.100
  Duration: 00:00:30.00, start: 0.000000, bitrate: 344 kb/s
    Stream #0:0: Video: vp8, yuv420p(progressive), 1280x720, SAR 1:1 DAR 16:9, 24 fps, 24 tbr, 1k tbn, 1k tbc (default)
    Stream #0:1: Audio: vorbis, 44100 Hz, stereo, fltp (default)
At least one output file must be specified
$ ffmpeg -i big_buck_bunny_0_30.webm -codec copy -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
  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, matroska,webm, from 'big_buck_bunny_0_30.webm':
  Metadata:
    encoder         : Lavf57.25.100
  Duration: 00:00:30.00, start: 0.000000, bitrate: 344 kb/s
    Stream #0:0: Video: vp8, yuv420p(progressive), 1280x720, SAR 1:1 DAR 16:9, 24 fps, 24 tbr, 1k tbn, 1k tbc (default)
    Stream #0:1: Audio: vorbis, 44100 Hz, stereo, fltp (default)
Output #0, null, to 'pipe:':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: vp8, yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 24 fps, 24 tbr, 1k tbn, 1k tbc (default)
    Stream #0:1: Audio: vorbis, 44100 Hz, stereo, fltp (default)
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=  720 fps=0.0 q=-1.0 Lsize=N/A time=00:00:29.99 bitrate=N/A speed= 909x    
video:856kB audio:387kB subtitle:0kB other streams:0kB global headers:4kB muxing overhead: unknown

But looking at the code that extracts the duration from this output, without this PR, it still reads the Duration: data, not the time= data from the end.

I've also simplified the code by removing the special case for GIFs, as they have always been using the better way of doing it.

@tburrows13 tburrows13 added the bug-fix For PRs and issues solving bugs. label Jun 8, 2020
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.07%) to 67.456% when pulling e2d08f8 on tburrows13:add-decode_video-option into 8e305c2 on Zulko:master.

@coveralls
Copy link

coveralls commented Oct 3, 2020

Coverage Status

Coverage decreased (-0.07%) to 67.456% when pulling e2d08f8 on tburrows13:add-decode_video-option into 8e305c2 on Zulko:master.

@tburrows13
Copy link
Collaborator Author

Most of the original comment is outdated. I've reverted the decoding behaviour back to how it was before with an option to fully decode the file if the user needs it. I've also changed the default fps source to 'fps' rather than 'tbr' as 'tbr' was causing quite a few issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-fix For PRs and issues solving bugs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants