FORUMS: list search recent posts

FFMpeg cuts off the ending of some movies

COW Forums : FFmpeg

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Jonathan Dupin
FFMpeg cuts off the ending of some movies
on Feb 11, 2015 at 3:37:03 pm

Im having a problem converting avi files to mp2. For the most part my script works fine, but some files (especially long movies) will come out with the end cut off.
Specifically, the last avi it did that with was 2:23 long, but the resulting mp2 was only 1:49 long.
The script uses 2 pass encoding and I set the filesize to fit on a standard dvd. However, for some reason instead of shrinking the movie to fit, it just cuts it off when it hits that filesize.
Using ffmpeg v 2.4.6-2 on a laptop with a single core processor running fedora 21.

I run the following command:
[CODE]
ffmpeg -y -i "$file" -pass 1 -passlogfile "$filename" -loglevel warning -filter:v "scale='w=min(720,trunc((480*33/40*dar)/2+0.5)*2):h=min(480,trunc((720*40/33/dar)/2+0.5)*2)',pad='w=720:h=480:x=(ow-iw)/2:y=(oh-ih)/2',setsar='r=40/33'" -target ntsc-dvd "$filename-null".mpg 2> ~/Videos/Convert/log/"encode-$filename".txt;

rm -f "$filename-null".mpg;

ffmpeg -y -i "$file" -pass 2 -passlogfile "$filename" -loglevel warning -filter:v "scale='w=min(720,trunc((480*33/40*dar)/2+0.5)*2):h=min(480,trunc((720*40/33/dar)/2+0.5)*2)',pad='w=720:h=480:x=(ow-iw)/2:y=(oh-ih)/2',setsar='r=40/33'" -fs 4680000000 -target ntsc-dvd -async 48000 "$filename-tmp".mpg 2>> ~/Videos/Convert/log/"encode-$filename".txt;

rm -f "$filename"-0.log;
[/CODE]

The log file only outputs the following error a few times, which seems to me in inconsequential.

[ac3 @ 0xfb0740] exponent out-of-range
[ac3 @ 0xfb0740] error decoding the audio block


Anyone have any idea whats going on or how to correct this problem? All assistance is appreciated :)


Return to posts index

Lou Logan
Re: FFMpeg cuts off the ending of some movies
on Feb 11, 2015 at 6:15:12 pm

How can this issue be duplicated?
Does it occur with just one pass?
What are you using to determine the durations?
What does ffmpeg say about the output durations? ffmpeg -i input1 -i input2
Most importantly, can you provide the complete console outputs from your commands?


Return to posts index

Jonathan Dupin
Re: FFMpeg cuts off the ending of some movies
on Feb 11, 2015 at 10:45:07 pm

I havent figured out a common factor that causes it, except maybe large file size/hd video. All the movies I convert are usually avi/ac3. So the only way I can duplicate is to encode a large file with these settings, though not all of them do it. Usually only one in 10 or 12.
From what I have tried, if I dont use 2 pass then filesize cap wont be enforced, and it comes out huge.
I use the log file (as well as using vlc player to test input and output) to determine durations.

My console output is as follows:


ffmpeg version 2.4.6 Copyright (c) 2000-2015 the FFmpeg developers
built on Feb 1 2015 02:48:47 with gcc 4.9.2 (GCC) 20141101 (Red Hat 4.9.2-1)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --enable-bzlib --disable-crystalhd --enable-frei0r --enable-gnutls --enable-libass --enable-libcdio --enable-libdc1394 --disable-indev=jack --enable-libfreetype --enable-libgsm --enable-libmp3lame --enable-openal --enable-opencl --enable-libopencv --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-x11grab --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-runtime-cpudetect
libavutil 54. 7.100 / 54. 7.100
libavcodec 56. 1.100 / 56. 1.100
libavformat 56. 4.101 / 56. 4.101
libavdevice 56. 0.100 / 56. 0.100
libavfilter 5. 1.100 / 5. 1.100
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 0.100 / 3. 0.100
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 0.100 / 53. 0.100
[avi @ 0x24ed200] non-interleaved AVI
Input #0, avi, from 'The.Hobbit.2014.Battle.Of.The.Five.Armies.2014.DVDScr.XVID.AC3.HQ.Hive-CM8.avi':
Metadata:
encoder : AVI-Mux GUI 1.17.7, Aug 8 2006 20:59:17
JUNK :
Duration: 02:24:17.30, start: 0.000000, bitrate: 1910 kb/s
Stream #0:0: Video: mpeg4 (Advanced Simple Profile) (XVID / 0x44495658), yuv420p, 720x304 [SAR 1:1 DAR 45:19], 1679 kb/s, 29.97 fps, 29.97 tbr, 29.97 tbn, 29.97 tbc
Stream #0:1: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, stereo, fltp, 224 kb/s
Metadata:
title : final_fixed
-async is forwarded to lavfi similarly to -af aresample=async=48000:min_hard_comp=0.100000:first_pts=0.
Output #0, dvd, to 'The.Hobbit.2014.Battle.Of.The.Five.Armies.2014.DVDScr.XVID.AC3.HQ.Hive-CM8-null.mpg':
Metadata:
JUNK :
encoder : Lavf56.4.101
Stream #0:0: Video: mpeg2video, yuv420p, 720x480 [SAR 40:33 DAR 20:11], q=2-31, pass 1, 6000 kb/s, 29.97 fps, 90k tbn, 29.97 tbc
Metadata:
encoder : Lavc56.1.100 mpeg2video
Stream #0:1: Audio: ac3, 48000 Hz, stereo, fltp, 448 kb/s
Metadata:
title : final_fixed
encoder : Lavc56.1.100 ac3
Stream mapping:
Stream #0:0 -> #0:0 (mpeg4 (native) -> mpeg2video (native))
Stream #0:1 -> #0:1 (ac3 (native) -> ac3 (native))
Press [q] to stop, [?] for help
[mpeg4 @ 0x2529460] Video uses a non-standard and wasteful way to store B-frames ('packed B-frames'). Consider using a tool like VirtualDub or avidemux to fix it.
frame= 48 fps=0.0 q=2.0 size= 1148kB time=00:00:01.62 bitrate=5781.4kbits/s dup=1 drop=0
frame= 106 fps=104 q=2.0 size= 2104kB time=00:00:03.54 bitrate=4859.8kbits/s dup=1 drop=0
frame= 154 fps=101 q=2.0 size= 2956kB time=00:00:05.11 bitrate=4734.5kbits/s dup=1 drop=0
frame= 210 fps=104 q=2.0 size= 3942kB time=00:00:07.00 bitrate=4611.5kbits/s dup=1 drop=0
frame= 284 fps=112 q=2.0 size= 4692kB time=00:00:09.49 bitrate=4046.6kbits/s dup=1 drop=0
frame= 367 fps=121 q=2.0 size= 5278kB time=00:00:12.25 bitrate=3529.4kbits/s dup=1 drop=0
frame= 453 fps=128 q=2.0 size= 5870kB time=00:00:15.09 bitrate=3184.9kbits/s dup=1 drop=0
frame= 553 fps=137 q=2.0 size= 6236kB time=00:00:18.45 bitrate=2767.6kbits/s dup=1 drop=0
frame= 628 fps=138 q=2.0 size= 7244kB time=00:00:20.92 bitrate=2836.3kbits/s dup=1 drop=0
frame= 676 fps=134 q=2.0 size= 8936kB time=00:00:22.52 bitrate=3250.2kbits/s dup=1 drop=0

[edit - i remove a bunch of these lines as it goes on for several hundred lines. this continues for a while until eventually...]


frame=196236 fps=113 q=2.0 size= 4560170kB time=01:49:07.70 bitrate=5705.3kbits/s dup=1 drop=0
frame=196290 fps=113 q=2.0 size= 4561966kB time=01:49:09.53 bitrate=5706.0kbits/s dup=1 drop=0
frame=196345 fps=113 q=2.0 size= 4563766kB time=01:49:11.38 bitrate=5706.6kbits/s dup=1 drop=0
frame=196407 fps=113 q=2.0 size= 4565078kB time=01:49:13.40 bitrate=5706.5kbits/s dup=1 drop=0
frame=196466 fps=113 q=2.0 size= 4566514kB time=01:49:15.41 bitrate=5706.6kbits/s dup=1 drop=0
frame=196518 fps=113 q=2.0 size= 4568426kB time=01:49:17.14 bitrate=5707.4kbits/s dup=1 drop=0
frame=196577 fps=113 q=2.0 size= 4569986kB time=01:49:19.13 bitrate=5707.7kbits/s dup=1 drop=0
frame=196589 fps=113 q=2.0 Lsize= 4570366kB time=01:49:19.48 bitrate=5707.8kbits/s dup=1 drop=0
video:4122103kB audio:358722kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.998322%


Return to posts index


Lou Logan
Re: FFMpeg cuts off the ending of some movies
on Feb 12, 2015 at 1:27:17 am

Please use the code button to format your commands and console outputs.

I should have looked more closely at your second-pass command. It contains this:
-fs 4680000000

Which means the encoding will stop once the output reaches 4680000000 bytes. If you want it to fit a DVD then you have to do some math (unless -target ntsc-dvd handles it...I don't recall):
bitrate = file size/duration
Or more specifically (source):
video bitrate = (target_size_in_Mbytes - sound_size_in_Mbytes) * 1024 * 1024 / length_in_secs * 8 / 1000

See example.

Also, your second pass contains "-async 48000". Is this necessary?


Return to posts index

Jonathan Dupin
Re: FFMpeg cuts off the ending of some movies
on Feb 13, 2015 at 12:53:26 pm
Last Edited By Jonathan Dupin on Feb 13, 2015 at 12:56:50 pm

thanks for your answer. that explains why its doing that. I took out fs and put in some code that does that math automatically for each file. I set the target size for 36000000 which is around 4.45gb (I couldnt use exactly 4.6gb cuz the -b:v option sets an "average bitrate" and some files go a little over dvd size to 4.9)
I use async to dynamically sync the audio. Had a few sync problems and this fixed it. The scale filter included in this code will take a video of any aspect and proportion/pad it to show properly in a dvd player without skewing or stretching.

Someone may find this code useful as it will take essentially any input video and produce a good looking properly padded dvd compatible mpeg2 with the audio syncronized (assuming the input file is in sync, of course). And now it will properly fit a dvd disc without cutting the end off.
Note: it pipes the console output into an encodelog in your home Videos folder.
thanks again for your help. :)


convert () {
file=$1;

echo "Converting '$file' to mpeg2 format.";
filename="${file%.*}";

#determine input movie duration in seconds, remove decimal point, and add 1 to round up the decimal
dur="$(/usr/bin/ffprobe -i "$file" -show_format -v quiet | sed -n 's/duration=//p' | sed 's/[.].*$//')";
((dur++));

#audio bit rate. Needs to be set for video bitrate calculation.
abr=224;

#calculate maximum average video bitrate needed to meet target filesize
vbr=$(echo "(36000000-$abr*$dur)/$dur" | bc);

#pass 1
ffmpeg -y -i "$file" -pass 1 -passlogfile "$filename" -filter:v "scale='w=min(720,trunc((480*33/40*dar)/2+0.5)*2):h=min(480,trunc((720*40/33/dar)/2+0.5)*2)',pad='w=720:h=480:x=(ow-iw)/2:y=(oh-ih)/2',setsar='r=40/33'" -target ntsc-dvd -b:v "$vbr"K -b:a "$abr"K -async 48000 "$filename-null".mpg 2> ~/Videos/"encodelog-$filename".txt;

#remove file created by pass 1 and no longer needed
rm -f "$filename-null".mpg;

#pass 2
ffmpeg -y -i "$file" -pass 2 -passlogfile "$filename" -filter:v "scale='w=min(720,trunc((480*33/40*dar)/2+0.5)*2):h=min(480,trunc((720*40/33/dar)/2+0.5)*2)',pad='w=720:h=480:x=(ow-iw)/2:y=(oh-ih)/2',setsar='r=40/33'" -target ntsc-dvd -b:v "$vbr"K -b:a "$abr"K -async 48000 "$filename-isothis".mpg 2>> ~/Videos/"encodelog-$filename".txt;

#removing log file created during 2 pass encoding and no longer needed
rm -f "$filename"-0.log;

echo "Conversion complete.";
}


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]