Skip to content
TheChatArchiveThe Chat Archive
gpt-4-1106-preview· openaiHugging Face Suzhen/CodeChat

Hey, write me FFMPEG Command to convert an MKV 1080p video into 100MB Mp4 video with…

  1. User

    Hey, write me FFMPEG Command to convert an MKV 1080p video into 100MB Mp4 video with Subtitles hard coded into video, Subtitles should be using arial bold font, size 12 (like FontName=Arial-Bold,FontSize=12'). For your information, video duration is around 24 minutes so do your calculations to set proper bitrate so that it's around 100MB

    No matter what, I want video to be exact 100MB or below of it. It doesn't matter if it loses quality but try using good encodes to make quality loss at minimum!

    the subtitle is available inside the video itself. It's not external. So try getting subtitle from within input video.

    use SVT-AV1 encoder!

  2. Assistant

    To achieve the desired output using FFmpeg with the constraints specified, we'll need to calculate the bitrate for the video encoding to target a file size of approximately 100MB (which is 819,200 kilobits) while including the desired subtitles hard-coded into the video.

    The command will include steps for extracting subtitles, re-encoding the video, and merging the subtitles with the video stream using the SVT-AV1 encoder. However, FFmpeg has limited support for SVT-AV1 as of my knowledge cutoff date. You will need to make sure you have the SVT-AV1 plugin installed and correctly set up with FFmpeg.

    Here's an example command that attempts to meet the specified requirements:

    ffmpeg -i input.mkv -map 0:s:0 -c:s text subtitles.srt
    ffmpeg -i input.mkv -vf subtitles=subtitles.srt:force_style='FontName=Arial-Bold,FontSize=12' -c:v libsvtav1 -b:v BITRATE -pass 1 -f mp4 /dev/null && \
    ffmpeg -i input.mkk -vf subtitles=subtitles.srt:force_style='FontName=Arial-Bold,FontSize=12' -c:v libsvtav1 -b:v BITRATE -pass 2 -c:a aac -b:a AUDIO_BITRATE output.mp4
    

    Let's break down the command:

    • The -i input.mkv specifies the input file.
    • The -map 0:s:0 selects the first subtitle stream from the input file.
    • The -c:s text tells FFmpeg to convert the subtitle to a text-based format and writes it to subtitles.srt.
    • The -vf subtitles=subtitles.srt:force_style='FontName=Arial-Bold,FontSize=12' filters the video stream to hardcode the subtitles with the stated font and size.
    • The -c:v libsvtav1 specifies the video codec to be used (SVT-AV1).
    • The BITRATE is the video bitrate that we will calculate to help the final video size be near 100MB.
    • The -pass 1 and -pass 2 are the two-pass encoding for better bitrate allocation.
    • The -f mp4 forces the output format to be MP4.

    First, you need to estimate the total bitrate to target a 100MB file for the length of your video. The total bitrate includes both video and audio bitrates. To do that, you'll use the following formula:

    Total Bitrate (kbps) = (Total File Size (kB) * 8) / Video Duration (seconds)
    

    Given a video duration of 24 minutes (or 1440 seconds) and aiming for a 100MB file size, and assuming that we'll allocate 128kbps for audio bitrate, let's calculate the video bitrate:

    Total File Size = 100 * 1024 = 102400 kB
    Audio Bitrate = 128 kbps
    Video Duration = 24 * 60 = 1440 seconds
    
    Total Bitrate = (102400 * 8) / 1440 - 128 = 556.44 kbps (We'll round it down to 550kbps for video bitrate)
    

    Now let's update the FFmpeg command with the correct BITRATE:

    ffmpeg -i input.mkv -map 0:s:0 -c:s text subtitles.srt
    ffmpeg -i input.mkv -vf subtitles=subtitles.srt:force_style='FontName=Arial-Bold,FontSize=12' -c:v libsvtav1 -b:v 550k -pass 1 -f mp4 /dev/null && \
    ffmpeg -i input.mkv -vf subtitles=subtitles.srt:force_style='FontName=Arial-Bold,FontSize=12' -c:v libsvtav1 -b:v 550k -pass 2 -c:a aac -b:a 128k output.mp4
    

    Please note that this is a simplification and the actual file size may not be exactly 100MB due to overheads and encoding complexity. Fine-tuning may be required. Additionally, make sure you have SVT-AV1 codec installed. If not, you may need to use a different encoder that is supported by FFmpeg, such as libx265 for HEVC / H.265 encoding or libx264 for AVC / H.264 encoding, which are more commonly used and supported by FFmpeg.

  3. User

    Amazing Job!

  4. Assistant

    Thank you! I'm glad you're satisfied with the response. If you have any more questions about FFmpeg, video encoding, or any other topic, feel free to ask. Good luck with your video conversion, and remember to test the command and adjust as necessary for your specific use case. Happy encoding!

  5. User

    Can (a== 1 && a==2 && a==3) ever evaluate to true in JavaScript?

  6. Assistant

    In JavaScript, under normal circumstances, a variable can hold only one value at a time, so the expression (a == 1 && a == 2 && a == 3) would normally evaluate to false. Because equality comparisons are performed one by one, if a is strictly equal to 1, it cannot be strictly equal to 2 or 3 at the same time.

    However, with a creative use of JavaScript's features, specifically the loose equality operator (==) and object coercion, the expression can be forced to evaluate to true. This can be demonstrated by providing an object with a custom toString or valueOf method that changes its output every time it's called:

    const a = {
      value: 0,
      valueOf: function() {
        this.value += 1;
        return this.value;
      }
    };
    
    if (a == 1 && a == 2 && a == 3) {
      console.log('This is true!');
    } else {
      console.log('This is false.');
    }
    

    This code will log 'This is true!' to the console.

    Here's how it works:

    • The object a has a valueOf method that increments its value property every time the method is called.
    • The loose equality operator (==) triggers coercion, converting our object to a primitive value. Whenever a is compared with a number, valueOf is called.
    • The first comparison a == 1 triggers valueOf, which increments the value from 0 to 1, so the comparison returns true.
    • The second comparison a == 2 triggers valueOf again, value increments to 2, making this comparison true.
    • The third comparison a == 3 does the same, increments value to 3, and is also true.

    As a result, the entire condition (a == 1 && a == 2 && a == 3) evaluates to true. This is a bit of a contrived example that takes advantage of JavaScript coercion and should not be used in production code, but it's an interesting example that showcases the flexibility and quirks of the language.