VideoHelp Forum
+ Reply to Thread
Results 1 to 2 of 2
  1. Member
    Join Date: Dec 2013
    Location: Los Altos
    Search Comp PM
    (I'm sorry for re-posting this, I can't find where I can edit my title in my previous post)

    Hi, I have a ffmpeg problem that I'm hoping someone can help me sort out:

    I'm trying to create a fade-in effect and fade-out effect on a video, but it ends up with some corruption.

    Here are the major steps I'm doing:

    1) get 3 second segment from the beginning of the video and 3 second segment from end of the video (and keeping a copy of the middle part)
    2) add fade in and fade out effects to the small begin/end clips
    3) rejoin the three clips back together for an overall fade-in/fade-out

    The corruption appears to only effect the middle segment of the video - I get Green Screen flashes, etc.

    (there are a few other minor steps I do which I will mention below)

    Here is a copy of the ffprobe on the input video (in case it helps)

    user@ubuntu:/var/www$ /home/user/bin/ffprobe all.mp4
    ffprobe version git-2013-12-06-59398c1 Copyright (c) 2007-2013 the FFmpeg developers
    built on Nov 30 2013 09:45:12 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
    configuration: --prefix=/home/user/ffmpeg_build --extra-cflags=-I/home/user/ffmpeg_build/include --extra-ldflags=-L/home/user/ffmpeg_build/lib --bindir=/home/user/bin --extra-libs=-ldl --enable-gpl --enable-libass --enable-libfdk-aac --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree
    libavutil 52. 56.100 / 52. 56.100
    libavcodec 55. 45.100 / 55. 45.100
    libavformat 55. 22.100 / 55. 22.100
    libavdevice 55. 5.102 / 55. 5.102
    libavfilter 3. 92.100 / 3. 92.100
    libswscale 2. 5.101 / 2. 5.101
    libswresample 0. 17.104 / 0. 17.104
    libpostproc 52. 3.100 / 52. 3.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'all.mp4':
    major_brand : isom
    minor_version : 512
    compatible_brands: isomiso2avc1mp41
    encoder : Lavf55.22.100
    Duration: 00:00:14.14, start: 0.000000, bitrate: 5980 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 5762 kb/s, 29.97 fps, 30 tbr, 30k tbn, 59.94 tbc (default)
    handler_name : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 235 kb/s (default)
    handler_name : SoundHandler

    I have a routine that will tell me the number of seconds in a video, the all.mp4 video is 14 seconds in length

    Here is my command I am using to extract the three parts of the video:
    ffmpeg -y -i /var/www/all.mp4 -vcodec copy -acodec copy -ss 00:00:00 -to 00:00:03 -sn /var/www/a.tmp.mp4 \
    -vcodec copy -acodec copy -ss 00:00:03 -to 00:00:11 -sn /var/www/b.tmp.mp4 \
    -vcodec copy -acodec copy -ss 00:00:11 -to 00:00:14 -sn /var/www/c.tmp.mp4

    I have a routine that counts the number of frames in a segment, I use it on the a.tmp.mp4 and c.tmp.mp4 files (python code below)
    cmd = "ffmpeg -i " + fileName + " -vcodec copy -f rawvideo -y /dev/null 2>&1"

    I look at the output and find the number of frames: (python code below)
    numFrames ='frame\W+(\d+)', output).group(1)

    using the numFrames for a.tmp.mp4 (89) and c.tmp.mp4 (58) I add the fade in and fade out effect:

    ffmpeg -i /var/www/a.tmp.mp4 -vf 'fade=in:0:89' -y /var/www/a_withfade.tmp.mp4
    ffmpeg -i /var/www/c.tmp.mp4 -vf 'fade=out:0:58' -y /var/www/c_withfade.tmp.mp4

    I then create a concat.txt file with the contents:
    file 'a_withfade.tmp.mp4'
    file 'b.tmp.mp4'
    file 'c_withfade.tmp.mp4'

    ffmpeg -f concat -i /var/www/concat.txt -c copy -y /var/www/all.mp4

    (yes, I want to overwrite my original file)

    I have examined each of the three parts of the video individually and they all play fine
    (ie, a_withfade.tmp.mp4, b.tmp.mp4 and c_withfade.tmp.mp4)

    As I mentioned, the middle portion becomes corrupted as a result of the joining of the files.

    Any pointers would be appreciated, I have been working with video for a week+ now so I'm still somewhat of a newcomer to ffmpeg, etc.

    I'm guessing that this has to do with the way the mp4 video is compressed vs rawvideo but I'm not really sure.

    I have found that some people have fixed corrupted videos using a command like the following (which doesn't help me):
    ffmpeg -i all.mp4 -vcodec copy -acodec copy all_fixed.mp4

    I can upload the video if it will help, but I suspect that it won't help with this problem.
    Quote Quote  
  2. Member
    Join Date: Dec 2013
    Location: Los Altos
    Search Comp PM

    I have a partial solution, there still are some problems with the resulting output, the frames sometimes freeze in the final video. But the Green screen flashes are gone.

    Using the three files from the previous post:

    I found some information at this web page:,%20merge)%20media%20files
    search for this line:
    If you have MP4 files, these could be losslessly concatenated by first transcoding them to mpeg transport streams. With h.264 video and AAC audio, the following can be used:

    ffmpeg -i a_withfade.tmp.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts i_a.ts
    ffmpeg -i b.tmp.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts i_b.ts
    ffmpeg -i c_withfade.tmp.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts i_c.ts

    then join them back together:
    ffmpeg -i "concat:i_a.ts|i_b.ts|i_c.ts" -c copy -bsf:a aac_adtstoasc abc.mp4

    some output errors show up: (many copies of this line)
    [mp4 @ 0x36fa6a0] Non-monotonous DTS in output stream 0:0; previous: 553728, current: 553728; changing to 553729. This may result in incorrect timestamps in the output file.

    I still have a problem with this solution: Some frames freeze
    Quote Quote  

Similar Threads