Newest 'ffmpeg' Questions - Stack Overflow

Les articles publiés sur le site

  • FFMpeg - Video conversion - .OGG to .MP4

    21 septembre, par Hue Man

    After scouring the net, I can't find anyone else trying to do this: Convert an OGG video format to MP4 video (usualy people are doing this the other way round). I have FFMpeg working just fine converting WEBM to MP4 but it just doesn't seem to like OGG files. The official FFMpeg documentation says that it can both Encode AND Decode OGG files but for some reason it isn't. Any ideas?

  • H264/MP4 live stream from ffmpeg does not work in browser

    21 septembre, par paunescuionica

    I cannot visualize a H264/MP4 stream generated by ffmpeg in Chrome, IE, Edge. It works only in Firefox.

    My testing environment is Windows 10, all updates done, all browsers up to date.

    I have a source MJPEG stream, which I need to transcode to H264/MP4 and show it in browser in a HTML5 element. In order to provide a working example, I use here this MJPEG stream: In my real case I have MJPEG input from different sources like IP cameras. I use the following command line:

    ffmpeg.exe -use_wallclock_as_timestamps 1 -f mjpeg -i "" -f mp4 -c:v libx264 -an -preset ultrafast -tune zerolatency -movflags frag_keyframe+empty_moov+faststart -reset_timestamps 1 -vsync 1 -flags global_header -r 15 "tcp://"

    If I try to visualize the output in VLC, I use this link: tcp:// and it works. Then I try to visualize the stream in browser, so I put this into a html document:


    If I open the document in Firefox it works just fine. But it does not work when trying to open in Chrome, IE or Edge. It seems that the browser tries to connect to the TCP server exposed by ffmpeg, but something happens because ffmpeg exits after few seconds.

    In ffmpeg console I can see this:

    av_interleaved_write_frame(): Unknown error
    Error writing trailer of tcp:// Error number -10053 occurred

    If I inspect the video element in Chrome is can see this error:

    Failed to load resource: net::ERR_INVALID_HTTP_RESPONSE

    As far as I know all these browsers should support H264 encoded streams transported in MP4 containers. If in the element I replace the link with a local link to a mp4/H264 encoded file, it is played just fine in each browser. The problem seems to be related to live streaming.

    Does anyone know why this happens and how it can be solved?

    Thank you!

  • How do i force ffmpeg to keep sizes divisible by 2 while maintaining aspect ratio ?

    21 septembre, par Alexander Novikov

    for example, this command line:

    ffmpeg -i rtsp:// -vf "scale=w=416:h=234:force_original_aspect_ratio=decrease" -an -f rawvideo -pix_fmt yuv420p -r 15 -

    works fine except if the source video was 360x240, output will be 351x234. which kinda sucks as yuv420p video with odd sizes is difficult to handle due to the way colour data is stored.

    is there a way i could force ffmpeg to give nearest possible even values?

  • python ffmpeg subprocess not working on heroku

    21 septembre, par Liam

    I've made a bot that deals with gif files and I tried uploading it on heroku.

    So I've installed this buildpack

    And I run this code as a subprocess:

    id_name = "je4d" (is actually randomized bc it downloads different gifs)
    path = "./media/%s.gif" % (id_name)'ffmpeg -y -ignore_loop 0 -i %s -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -t 15 %s' % (path, path.replace(".gif", ".mp4")), shell=True)

    So if I run this on my computer, it will transform je4d.gif into an .mp4 and it works fine

    If I try to test ffmpeg on heroku by doing heroku run bash and then inputing the command ffmpeg -y -ignore_loop 0 -i ./media/je4d.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -t 15 ./media/je4d.mp4 It also works fine and makes a .mp4

    However if I run the code on heroku from python it does this: [Errno 2] No such file or directory: 'ffmpeg -y -i ./media/3s1m8cw09sl11.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" ./media/3s1m8cw09sl11.mp4': 'ffmpeg -y -i ./media/3s1m8cw09sl11.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" ./media/3s1m8cw09sl11.mp4'

    So I thought maybe there's an error with the download, so I change path to a static file on the server, and it still gives me the same error. Any tips?

  • FFmpeg in Python File already exists error

    21 septembre, par Abdul Rehman

    I'm working on a project using python(3.6) and Django(2.0) in which i'm converting a video to mp4 if it's in any other formate.

    Here's my code:


    def generate_thumbnail(filename, thumb_name):
        print('func called')
        video_input_path = os.path.join(filename)
        img_output_path = os.path.join(thumb_name)['ffmpeg', '-i', video_input_path, '-ss', '00:00:00.000', 'vframes', '1', img_output_path])
    def convert_to_mp4(video_name, only_name):
            "ffmpeg -i '{input}' -ac 2 -b:v 2000k -c:a aac -c:v libx264 -b:a 160k -vprofile high -bf 0 -strict experimental -f mp4 '{output}.mp4'".format(
                input=video_name, output=only_name))
        return True
    def perform_upload(video, thumbnail):
        print('vdieo name is: {}'.format(video))
        servise ='storage', 'v1', credentials=credentials)
        bucket_name = 'test_bucket004'
        print('Uploading the video...')
        media = MediaFileUpload(video, chunksize=4149304, mimetype='video/mp4',
        req = servise.objects().insert(
            body={"cacheControl": "public,max-age=31536000"},
        resp = None
        while resp is None:
            status, resp = req.next_chunk()
        video_url = '' + bucket_name + '/' + str(video)
        print('Uploading your thumbnail...')
        media = MediaFileUpload(thumbnail, chunksize=4149304, mimetype='image/jpeg',
        req = servise.objects().insert(
            body={"cacheControl": "public,max-age=31536000"},
        resp = None
        while resp is None:
            status, resp = req.next_chunk()
        thumb_url = '' + bucket_name + '/' + str(thumbnail)
        return video_url, thumb_url
    class VideoConverter(generics.ListCreateAPIView):
        def get(self, request, *args, **kwargs):
            return HttpResponse('Get request', status=200)
        def post(self, request, *args, **kwargs):
            serializer = VideoConverterSerializer(
            validation = serializer.is_valid()
            if validation is True:
                url = request.POST.get('video_url')
                filename = url.split('/')
                filename = filename[-1]
                ext = filename.split('.')
                only_name = ext[0]
                urllib.request.urlretrieve(url, filename)
                generate_thumbnail(filename, only_name + '_thumbnail.jpg')
                if ext == 'mp4':
                    videourl, thumb_url = perform_upload(filename, only_name + '_thumbnail.jpg')
                    conversion = convert_to_mp4(filename, only_name)
                    if conversion is True:
                        videourl, thumb_url = perform_upload(only_name + '.mp4', only_name + '_thumbnail.jpg')
                return HttpResponse('Video url is: {}\n \nThumbnail url is: {}'.format(videourl, thumb_url))
                return HttpResponse('Not a valid request')

    But when I pass it a video of Mp4 format it returns an error in the IDE console like this:

    ffmpeg version 4.0.2 Copyright (c) 2000-2018 the FFmpeg developers built with Apple LLVM version 10.0.0 (clang-1000.10.43.1) configuration: --prefix=/usr/local/Cellar/ffmpeg/4.0.2 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma libavutil 56. 14.100 / 56. 14.100 libavcodec 58. 18.100 / 58. 18.100 libavformat 58. 12.100 / 58. 12.100 libavdevice 58. 3.100 / 58. 3.100 libavfilter 7. 16.100 / 7. 16.100 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 1.100 / 5. 1.100 libswresample 3. 1.100 / 3. 1.100 libpostproc 55. 1.100 / 55. 1.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'PHP_GCS.mp4': Metadata: major_brand : mp42 minor_version : 1 compatible_brands: mp41mp42isom creation_time : 2018-08-03T13:08:04.000000Z Duration: 00:01:21.40, start: 0.000000, bitrate: 1584 kb/s Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1918x1078 [SAR 1:1 DAR 137:77], 1581 kb/s, 30 fps, 30 tbr, 600 tbn, 1200 tbc (default) Metadata: creation_time : 2018-08-03T13:08:04.000000Z handler_name : Core Media Video

    File 'PHP_GCS.mp4' already exists. Overwrite ? [y/N]

    and stop the execution here until I press the enter button.I'm really confused why this is happining because when the video is already mp4 i'm not using ffmpeg but only for thumbnail generaton.

    What can be wrong here?

    Thanks in advance!