Newest 'ffmpeg' Questions - Stack Overflow

http://stackoverflow.com/questions/tagged/ffmpeg

Les articles publiés sur le site

  • Decoding mJPEG with libavcodec

    5 mai 2014, par dtumaykin

    I am creating video conference application. I have discovered that webcams (at least 3 I have) provide higher resolutions and framerates for mJPEG output format. So far I was using YUY2, converted in I420 for compression with X264. To transcode mJPEG to I420, I need to decode it first. I am trying to decode images from webcam with libavcodec. This is my code.

    Initialization:

    // mJPEG to I420 conversion
    AVCodecContext * _transcoder = nullptr;
    AVFrame * _outputFrame;
    AVPacket _inputPacket;
    
    avcodec_register_all();
    _outputFrame = av_frame_alloc();
    av_frame_unref(_outputFrame);
    av_init_packet(&_inputPacket);
    
    AVCodec * codecDecode = avcodec_find_decoder(AV_CODEC_ID_MJPEG);
    
    _transcoder = avcodec_alloc_context3(codecDecode);
    avcodec_get_context_defaults3(_transcoder, codecDecode);
    _transcoder->flags2 |= CODEC_FLAG2_FAST;
    _transcoder->pix_fmt = AVPixelFormat::AV_PIX_FMT_YUV420P;
    _transcoder->width = width;
    _transcoder->height = height;
    avcodec_open2(_transcoder, codecDecode, nullptr);
    

    Decoding:

    _inputPacket.size = size;
    _inputPacket.data = data;
    
    int got_picture;
    int decompressed_size = avcodec_decode_video2(_transcoder, _outputFrame, &got_picture, &_inputPacket);
    

    But so far, what I am getting is a green screen. Where am I wrong?

    UPD: I have enabled libavcodec logging, but there are not warnings or errors. Also I have discovered that _outputframe has AV_PIX_FMT_YUVJ422P as format and colorspace, which does not fit any on values in libavcodec's enums (the actual value is 156448160).

  • Is /usr/local/lib searched for shared libraries ?

    5 mai 2014, par Leo Izen

    Is /usr/local/lib searched for shared libraries ? I have this error:

    [Leo@chessman ~]$ whereis ffmpeg
    ffmpeg: /usr/local/bin/ffmpeg
    [Leo@chessman ~]$ ffmpeg
    ffmpeg: error while loading shared libraries: libavcore.so.0: cannot open shared object file: No such file or directory
    [Leo@chessman ~]$ ls /usr/local/lib/libav*
    /usr/local/lib/libavcodec.a            /usr/local/lib/libavfilter.a
    /usr/local/lib/libavcodec.so           /usr/local/lib/libavfilter.so
    /usr/local/lib/libavcodec.so.52        /usr/local/lib/libavfilter.so.1
    /usr/local/lib/libavcodec.so.52.108.0  /usr/local/lib/libavfilter.so.1.74.0
    /usr/local/lib/libavcore.a             /usr/local/lib/libavformat.a
    /usr/local/lib/libavcore.so            /usr/local/lib/libavformat.so
    /usr/local/lib/libavcore.so.0          /usr/local/lib/libavformat.so.52
    /usr/local/lib/libavcore.so.0.16.1     /usr/local/lib/libavformat.so.52.94.0
    /usr/local/lib/libavdevice.a           /usr/local/lib/libavutil.a
    /usr/local/lib/libavdevice.so          /usr/local/lib/libavutil.so
    /usr/local/lib/libavdevice.so.52       /usr/local/lib/libavutil.so.50
    /usr/local/lib/libavdevice.so.52.2.3   /usr/local/lib/libavutil.so.50.36.0
    [Leo@chessman ~]$ 
    
  • ffmpeg HLS creation and segmentation results in "cannot decode" on iPad

    5 mai 2014, par jt_dylan

    I have the following code that plays on Mac Safari:

    
    
        
           
           
           
    
        
    
    
    

    The url can be cut/pasted into the browser and works also but neither this code nor the url works in Windows Safari or iPad. Specifically on iPad I receive a cannot decode error. On Mac I have Quicktime installed so I tried that on Windows with no luck. The link that can be play on Mac is below.

    http://d1ckv7o9k6o3x9.cloudfront.net/d54cfa01-eff2-4e86-946e-dc8b2ee4a7e8/media/hls/MVI_5927.m3u8

    Browser Versions of software: Mac Safari: Version 7.0.3 (9537.75.14) (works) Windows Safari: Version 5.1.7 (7534.7.2) (doesn't work - blank screen) iPad Safari: ios Version 7.1.1 (doesn't work - cannot decode)

    Here is how I'm creating my mp4 (lgpl) I'm creating an mp4 with this command: ffmpeg -i input.mov c:v mpeg4 q:v 1 test.mp4

    I'm creating the hls using ffmpeg lpgl with this command:

    ffmpegcmd -re -y -i test.mp4 -map 0 -f segment -segment_list test.m3u8 -segment_list_flags +live -segment_time 1 -segment_list_type m3u8 test%05d.ts 2>&1
    

    Now this works in Mac Safari with Quicktime installed but results in "cannot decode" if I try the url from ipad Safari.

    I then tried with libx264 to create the mp4 as h.264 with aac and then copy to mpeg2 container as follows:

    ffmpeg -i test.mov  -c:v libx264 -c:a libfdk_aac -preset slower -b:a 240k test.slower.mp4
    ffmpeg -i test.slower.mp4 -vcodec copy -f mpegts -bsf h264_mp4toannexb test.slower.ts
    ffmpeg -re -y -i test.slower.ts -map 0 -f segment -segment_list test.slower.m3u8 -segment_list_flags +live -segment_time 1 -segment_list_type m3u8 test.slower.%05d.ts
    

    This still produces the same results. Any idea what is wrong here?

    Any help is much appreciated.

    Regards, jt_dylan

    Output from libx264 commands below:

    ffmpeg -i test.mov  -c:v libx264 -c:a libfdk_aac -preset slower -b:a 240k test.slower.mp4
    
    ffmpeg version git-2014-05-04-aeeb3d4 Copyright (c) 2000-2014 the FFmpeg developers
      built on May  4 2014 17:01:19 with gcc 4.6.3 (GCC) 20120306 (Red Hat 4.6.3-2)
      configuration: --prefix=/home/ec2-user/ffmpeg_build --extra-cflags=-I/home/ec2-user/ffmpeg_build/include --extra-ldflags=-L/home/ec2-user/ffmpeg_build/lib --bindir=/home/ec2-user/bin --extra-libs=-ldl --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264
      libavutil      52. 81.100 / 52. 81.100
      libavcodec     55. 60.103 / 55. 60.103
      libavformat    55. 37.102 / 55. 37.102
      libavdevice    55. 13.101 / 55. 13.101
      libavfilter     4.  5.100 /  4.  5.100
      libswscale      2.  6.100 /  2.  6.100
      libswresample   0. 18.100 /  0. 18.100
      libpostproc    52.  3.100 / 52.  3.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'tst/MVI_1716.MOV':
      Metadata:
        major_brand     : qt  
        minor_version   : 537331968
        compatible_brands: qt  CAEP
        creation_time   : 2012-07-21 05:17:44
      Duration: 00:00:20.06, start: 0.000000, bitrate: 34471 kb/s
        Stream #0:0(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuvj420p(pc, smpte170m), 1920x1080, 33663 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 48k tbc (default)
        Metadata:
          creation_time   : 2012-07-21 05:17:44
        Stream #0:1(eng): Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, mono, s16, 768 kb/s (default)
        Metadata:
          creation_time   : 2012-07-21 05:17:44
    No pixel format specified, yuvj420p for H.264 encoding chosen.
    Use -pix_fmt yuv420p for compatibility with outdated media players.
    [libx264 @ 0x39ae9e0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
    [libx264 @ 0x39ae9e0] profile High, level 5.0
    [libx264 @ 0x39ae9e0] 264 - core 142 r2 ac76440 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=8 deblock=1:0:0 analyse=0x3:0x133 me=umh subme=9 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=2 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=2 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=23 scenecut=40 intra_refresh=0 rc_lookahead=60 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
    Output #0, mp4, to 'tstconv/MVI_1716.slower.mp4':
      Metadata:
        major_brand     : qt  
        minor_version   : 537331968
        compatible_brands: qt  CAEP
        encoder         : Lavf55.37.102
        Stream #0:0(eng): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuvj420p, 1920x1080, q=-1--1, 24k tbn, 23.98 tbc (default)
        Metadata:
          creation_time   : 2012-07-21 05:17:44
        Stream #0:1(eng): Audio: aac (libfdk_aac) ([64][0][0][0] / 0x0040), 48000 Hz, mono, s16, 240 kb/s (default)
        Metadata:
          creation_time   : 2012-07-21 05:17:44
    Stream mapping:
      Stream #0:0 -> #0:0 (h264 -> libx264)
      Stream #0:1 -> #0:1 (pcm_s16le -> libfdk_aac)
    Press [q] to stop, [?] for help
    frame=  481 fps=1.5 q=-1.0 Lsize=   18428kB time=00:00:20.07 bitrate=7519.9kbits/s    
    video:17827kB audio:589kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.060811%
    [libx264 @ 0x39ae9e0] frame I:3     Avg QP:23.31  size:113718
    [libx264 @ 0x39ae9e0] frame P:135   Avg QP:25.06  size: 56912
    [libx264 @ 0x39ae9e0] frame B:343   Avg QP:27.13  size: 29825
    [libx264 @ 0x39ae9e0] consecutive B-frames:  1.2%  4.2% 20.6% 74.0%
    [libx264 @ 0x39ae9e0] mb I  I16..4: 20.0% 53.3% 26.6%
    [libx264 @ 0x39ae9e0] mb P  I16..4:  9.7% 22.8%  5.4%  P16..4: 41.0%  8.6%  5.4%  0.1%  0.0%    skip: 7.0%
    [libx264 @ 0x39ae9e0] mb B  I16..4:  3.3%  7.2%  2.0%  B16..8: 40.7%  9.8%  1.7%  direct: 6.3%  skip:29.0%  L0:49.6% L1:44.7% BI: 5.7%
    [libx264 @ 0x39ae9e0] 8x8 transform intra:58.9% inter:70.2%
    [libx264 @ 0x39ae9e0] direct mvs  spatial:99.4% temporal:0.6%
    [libx264 @ 0x39ae9e0] coded y,uvDC,uvAC intra: 58.6% 46.9% 7.3% inter: 23.9% 20.2% 0.2%
    [libx264 @ 0x39ae9e0] i16 v,h,dc,p: 10% 64% 14% 12%
    [libx264 @ 0x39ae9e0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu:  7% 50% 10%  3%  4%  3%  8%  4% 12%
    [libx264 @ 0x39ae9e0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu:  4% 64%  5%  2%  3%  2%  6%  2% 10%
    [libx264 @ 0x39ae9e0] i8c dc,h,v,p: 35% 53%  9%  3%
    [libx264 @ 0x39ae9e0] Weighted P-Frames: Y:11.1% UV:4.4%
    [libx264 @ 0x39ae9e0] ref P L0: 47.8% 12.2% 15.8%  6.8%  5.7%  4.2%  4.3%  2.6%  0.6%  0.0%
    [libx264 @ 0x39ae9e0] ref B L0: 76.8% 10.5%  5.1%  2.9%  2.2%  1.5%  0.9%
    [libx264 @ 0x39ae9e0] ref B L1: 94.6%  5.4%
    [libx264 @ 0x39ae9e0] kb/s:7279.24
    
    ffmpeg -i test.slower.mp4 -vcodec copy -f mpegts -bsf h264_mp4toannexb test.slower.ts
    
    ffmpeg version git-2014-05-04-aeeb3d4 Copyright (c) 2000-2014 the FFmpeg developers
      built on May  4 2014 17:01:19 with gcc 4.6.3 (GCC) 20120306 (Red Hat 4.6.3-2)
      configuration: --prefix=/home/ec2-user/ffmpeg_build --extra-cflags=-I/home/ec2-user/ffmpeg_build/include --extra-ldflags=-L/home/ec2-user/ffmpeg_build/lib --bindir=/home/ec2-user/bin --extra-libs=-ldl --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264
      libavutil      52. 81.100 / 52. 81.100
      libavcodec     55. 60.103 / 55. 60.103
      libavformat    55. 37.102 / 55. 37.102
      libavdevice    55. 13.101 / 55. 13.101
      libavfilter     4.  5.100 /  4.  5.100
      libswscale      2.  6.100 /  2.  6.100
      libswresample   0. 18.100 /  0. 18.100
      libpostproc    52.  3.100 / 52.  3.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'tstconv/MVI_1716.slower.mp4':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        encoder         : Lavf55.37.102
      Duration: 00:00:20.11, start: 0.042667, bitrate: 7508 kb/s
        Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc), 1920x1080, 7279 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
        Metadata:
          handler_name    : VideoHandler
        Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 240 kb/s (default)
        Metadata:
          handler_name    : SoundHandler
    [swscaler @ 0x367c0c0] deprecated pixel format used, make sure you did set range correctly
    Output #0, segment, to 'MVI_1716.slower.%05d.ts':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        encoder         : Lavf55.37.102
        Stream #0:0(eng): Video: mpeg2video, yuv420p, 1920x1080, q=2-31, 200 kb/s, 90k tbn, 23.98 tbc (default)
        Metadata:
          handler_name    : VideoHandler
        Stream #0:1(eng): Audio: mp2, 48000 Hz, mono, s16, 384 kb/s (default)
        Metadata:
          handler_name    : SoundHandler
    Stream mapping:
      Stream #0:0 -> #0:0 (h264 -> mpeg2video)
      Stream #0:1 -> #0:1 (aac -> mp2)
    Press [q] to stop, [?] for help
    frame=  482 fps= 24 q=31.0 Lsize=N/A time=00:00:20.12 bitrate=N/A dup=1 drop=0    
    video:8293kB audio:944kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 195032183209984.000000%
    ffmpeg version git-2014-05-04-aeeb3d4 Copyright (c) 2000-2014 the FFmpeg developers
      built on May  4 2014 17:01:19 with gcc 4.6.3 (GCC) 20120306 (Red Hat 4.6.3-2)
      configuration: --prefix=/home/ec2-user/ffmpeg_build --extra-cflags=-I/home/ec2-user/ffmpeg_build/include --extra-ldflags=-L/home/ec2-user/ffmpeg_build/lib --bindir=/home/ec2-user/bin --extra-libs=-ldl --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264
      libavutil      52. 81.100 / 52. 81.100
      libavcodec     55. 60.103 / 55. 60.103
      libavformat    55. 37.102 / 55. 37.102
      libavdevice    55. 13.101 / 55. 13.101
      libavfilter     4.  5.100 /  4.  5.100
      libswscale      2.  6.100 /  2.  6.100
      libswresample   0. 18.100 /  0. 18.100
      libpostproc    52.  3.100 / 52.  3.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'tstconv/MVI_1716.slower.mp4':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        encoder         : Lavf55.37.102
      Duration: 00:00:20.11, start: 0.042667, bitrate: 7508 kb/s
        Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc), 1920x1080, 7279 kb/s, 23.98 fps, 23.98 tbr, 24k tbn, 47.95 tbc (default)
        Metadata:
          handler_name    : VideoHandler
        Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 240 kb/s (default)
        Metadata:
          handler_name    : SoundHandler
    File 'tstconv/MVI_1716.slower.ts' already exists. Overwrite ? [y/N] y
    Output #0, mpegts, to 'tstconv/MVI_1716.slower.ts':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        encoder         : Lavf55.37.102
        Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), yuvj420p, 1920x1080, q=2-31, 7279 kb/s, 23.98 fps, 90k tbn, 23.98 tbc (default)
        Metadata:
          handler_name    : VideoHandler
        Stream #0:1(eng): Audio: mp2, 48000 Hz, mono, s16, 384 kb/s (default)
        Metadata:
          handler_name    : SoundHandler
    Stream mapping:
      Stream #0:0 -> #0:0 (copy)
      Stream #0:1 -> #0:1 (aac -> mp2)
    Press [q] to stop, [?] for help
    frame=  481 fps=0.0 q=-1.0 Lsize=   20334kB time=00:00:20.12 bitrate=8276.6kbits/s    
    video:17827kB audio:944kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 8.325850%
    
    ffmpeg -re -y -i test.slower.ts -map 0 -f segment -segment_list test.slower.m3u8 -segment_list_flags +live -segment_time 1 -segment_list_type m3u8 test.slower.%05d.ts
    
    ffmpeg version git-2014-05-04-aeeb3d4 Copyright (c) 2000-2014 the FFmpeg developers
      built on May  4 2014 17:01:19 with gcc 4.6.3 (GCC) 20120306 (Red Hat 4.6.3-2)
      configuration: --prefix=/home/ec2-user/ffmpeg_build --extra-cflags=-I/home/ec2-user/ffmpeg_build/include --extra-ldflags=-L/home/ec2-user/ffmpeg_build/lib --bindir=/home/ec2-user/bin --extra-libs=-ldl --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264
      libavutil      52. 81.100 / 52. 81.100
      libavcodec     55. 60.103 / 55. 60.103
      libavformat    55. 37.102 / 55. 37.102
      libavdevice    55. 13.101 / 55. 13.101
      libavfilter     4.  5.100 /  4.  5.100
      libswscale      2.  6.100 /  2.  6.100
      libswresample   0. 18.100 /  0. 18.100
      libpostproc    52.  3.100 / 52.  3.100
    Input #0, mpegts, from 'tstconv/MVI_1716.slower.ts':
      Duration: 00:00:20.11, start: 1.430733, bitrate: 8282 kb/s
      Program 1 
        Metadata:
          service_name    : Service01
          service_provider: FFmpeg
        Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuvj420p(pc), 1920x1080, 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc
        Stream #0:1[0x101](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, mono, s16p, 373 kb/s
    [swscaler @ 0x1fe9ae0] deprecated pixel format used, make sure you did set range correctly
        Output #0, segment, to 'MVI_1716.slower.%05d.ts':
          Metadata:
            encoder         : Lavf55.37.102
            Stream #0:0: Video: mpeg2video, yuv420p, 1920x1080, q=2-31, 200 kb/s, 90k tbn, 23.98 tbc
            Stream #0:1(eng): Audio: mp2, 48000 Hz, mono, s16, 384 kb/s
        Stream mapping:
          Stream #0:0 -> #0:0 (h264 -> mpeg2video)
          Stream #0:1 -> #0:1 (mp2 -> mp2)
    
  • Speed up video with FFmpeg with low I-frame distance [on hold]

    5 mai 2014, par Kevin Chromik

    I got a video with 60 fps and h264 encoded (.mp4), audio layer is removed. Now I want to speed up the video 4x faster with FFmpeg, but I would like to have a very low I-frame distance to be able to perform very precise and fast seeking. I don't need a high compression. Does someone has an idea how I could achieve that?

    Thanks in advance.

  • Can I convert a django video upload from a form using ffmpeg before storing the video ?

    5 mai 2014, par GetItDone

    I've been stuck for weeks trying to use ffmpeg to convert user uploaded videos to flv. I use heroku to host my website, and store my static and media files on amazon S3 with s3boto. The initial video file will upload fine, however when I retrieve the video and run a celery task (in the same view where the initial video file is uploaded), the new file won't store on S3. I've been trying to get this to work for over a month, with no luck, and really no good resources available for learning how to do this, so I figure maybe if I can get the ffmpeg task to run before storing the video I may be able to get it to work. Unfortunately I'm still not a very advanced at python (or django), so I don't even know if/how this is possible. Anyone have any ideas? I am willing to use any solution at this point no matter how ugly, as long as it successfully takes video uploads and converts to flv using ffmpeg, with the resulting file being stored on S3. It doesn't seem that my situation is very common, because no matter where I look, I cannot find a solution that explains what I should be trying to do. Therefore I will be very appreciative of any guidance. Thanks. My relevant code follows:

    #models.py
    def content_file_name(instance, filename):
        ext = filename.split('.')[-1]
        new_file_name = "remove%s.%s" % (uuid.uuid4(), ext)
        return '/'.join(['videos', instance.teacher.username, new_file_name])
    
    class BroadcastUpload(models.Model):
        title = models.CharField(max_length=50, verbose_name=_('Title'))
        description = models.TextField(max_length=100, verbose_name=_('Description'))
        teacher = models.ForeignKey(User, null=True, blank=True, related_name='teacher')
        created_date = models.DateTimeField(auto_now_add=True)
        video_upload = models.FileField(upload_to=content_file_name)
        flvfilename = models.CharField(max_length=100, null=True, blank=True)
        videothumbnail = models.CharField(max_length=100, null=True, blank=True)
    
    #tasks.py
    @task(name='celeryfiles.tasks.convert_flv')
    def convert_flv(video_id):
        video = BroadcastUpload.objects.get(pk=video_id)
        print "ID: %s" % video.id
        id = video.id
        print "VIDEO NAME: %s" % video.video_upload.name
        teacher = video.teacher
        print "TEACHER: %s" % teacher
        filename = video.video_upload
        sourcefile = "%s%s" % (settings.MEDIA_URL, filename)
        vidfilename = "%s_%s.flv" % (teacher, video.id)
        targetfile = "%svideos/flv/%s" % (settings.MEDIA_URL, vidfilename)
        ffmpeg = "ffmpeg -i %s %s" % (sourcefile, vidfilename)
        try:
            ffmpegresult = subprocess.call(ffmpeg)
            #also tried separately with following line:
            #ffmpegresult = commands.getoutput(ffmpeg)
            print "---------------FFMPEG---------------"
            print "FFMPEGRESULT: %s" % ffmpegresult
        except Exception as e:
            ffmpegresult = None
            print("Failed to convert video file %s to %s" % (sourcefile, targetfile))
            print(traceback.format_exc())
        video.flvfilename = vidfilename
        video.save()
    
    @task(name='celeryfiles.tasks.ffmpeg_image')        
    def ffmpeg_image(video_id):
        video = BroadcastUpload.objects.get(pk=video_id)
        print "ID: %s" %video.id
        id = video.id
        print "VIDEO NAME: %s" % video.video_upload.name
        teacher = video.teacher
        print "TEACHER: %s" % teacher
        filename = video.video_upload
        sourcefile = "%s%s" % (settings.MEDIA_URL, filename)
        imagefilename = "%s_%s.png" % (teacher, video.id)
        thumbnailfilename = "%svideos/flv/%s" % (settings.MEDIA_URL, thumbnailfilename)
        grabimage = "ffmpeg -y -i %s -vframes 1 -ss 00:00:02 -an -vcodec png -f rawvideo -s 320x240 %s" % (sourcefile, thumbnailfilename)
        try:        
             videothumbnail = subprocess.call(grabimage)
             #also tried separately following line:
             #videothumbnail = commands.getoutput(grabimage)
             print "---------------IMAGE---------------"
             print "VIDEOTHUMBNAIL: %s" % videothumbnail
        except Exception as e:
             videothumbnail = None
             print("Failed to convert video file %s to %s" % (sourcefile, thumbnailfilename))
             print(traceback.format_exc())
        video.videothumbnail = imagefilename
        video.save()
    
    #views.py
    def upload_broadcast(request):
        if request.method == 'POST':
            form = BroadcastUploadForm(request.POST, request.FILES)
            if form.is_valid():
                upload=form.save()
                video_id = upload.id
                image_grab = ffmpeg_image.delay(video_id)
                video_conversion = convert_flv.delay(video_id)
                return HttpResponseRedirect('/current_classes/')
        else:
            form = BroadcastUploadForm(initial={'teacher': request.user,})
        return render_to_response('videos/create_video.html', {'form': form,}, context_instance=RequestContext(request))
    
    #settings.py
    DEFAULT_FILE_STORAGE = 'myapp.s3utils.MediaRootS3BotoStorage'
    DEFAULT_S3_PATH = "media"
    STATICFILES_STORAGE = 'myapp.s3utils.StaticRootS3BotoStorage'
    STATIC_S3_PATH = "static"
    AWS_STORAGE_BUCKET_NAME = 'my_bucket'
    CLOUDFRONT_DOMAIN = 'domain.cloudfront.net'
    AWS_ACCESS_KEY_ID = 'MY_KEY_ID'
    AWS_SECRET_ACCESS_KEY = 'MY_SECRET_KEY'
    MEDIA_ROOT = '/%s/' % DEFAULT_S3_PATH
    MEDIA_URL = 'http://%s/%s/' % (CLOUDFRONT_DOMAIN, DEFAULT_S3_PATH)
    ...
    
    #s3utils.py
    from storages.backends.s3boto import S3BotoStorage
    from django.utils.functional import SimpleLazyObject
    
    StaticRootS3BotoStorage = lambda: S3BotoStorage(location='static')
    MediaRootS3BotoStorage  = lambda: S3BotoStorage(location='media')
    

    I can add any other info if needed to help me solve my problem.