'Dealing with mp4 files in memory with ffprobe

In the uploading file process, I want to manipulate the content in the memory without saving the file to the disk. For that purpose, I'm using FFmpeg with converting IFormFile into MemoryStream and further on I'm using FFmpeg to change the content and output the result into pipe again for further processing. This whole works fine with the exception that some files cannot be processed.

Again, I'm not dealing with direct files during the process but their memory stream representation.

When I examine 1st file details using ffprobe I'm getting

format": {
        "filename": "file_example_MP4_480_1_5MG.mp4",
        "nb_streams": 2,
        "nb_programs": 0,
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "start_time": "0.000000",
        "duration": "30.526667",
        "size": "1570024",
        "bit_rate": "411449",
        "probe_score": 100,
        "tags": {
            "major_brand": "mp42",
            "minor_version": "0",
            "compatible_brands": "mp42mp41isomavc1",
            "creation_time": "2015-08-07T09:13:02.000000Z"
        }
    }

Memory stream representation of this file as input pipe in the command can be processed and output as expected.

ffmpeg -f mp4 -i pipe:0 -c:v libx264 -movflags frag_keyframe+empty_moov -s 800x600 -f mpeg pipe:1

Error: update with full error message

Consider increasing the value for the 'analyzeduration' and 'probesize' options Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pipe:0': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf58.45.100 Duration: 00:00:46.64, start: 0.000000, bitrate: N/A Stream #0:0(und): Video: h264 (avc1 / 0x31637661), none, 960x400, 2882 kb/s, SAR 1:1 DAR 12:5, 23.98 fps, 23.98 tbr, 24k tbn, 48k tbc (default) Metadata: handler_name : GPAC ISO Video Handler Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 123 kb/s (default) Metadata: handler_name : GPAC ISO Audio Handler Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264)) Stream #0:1 -> #0:1 (aac (native) -> mp2 (native)) [mov,mp4,m4a,3gp,3g2,mj2 @ 0x55dfc34c2100] stream 0, offset 0x30: partial file pipe:0: Invalid data found when processing input Cannot determine format of input stream 0:0 after EOF Error marking filters as finished Conversion failed!

My question is: What do I need to change in the command to successfully finish the process with the second file?

Update:

I tried with -analyzeduration 2147483647 -probesize 2147483647 and with -probesize 4G -analyzeduration 10G but it still produces the same error.

ffmpeg -analyzeduration 2147483647 -probesize 2147483647 -f mp4 -i pipe:0 -c:v libx264 -movflags frag_keyframe+empty_moov -s 800x600 -f mpeg pipe:1

2nd Update: When I use -pix_fmt yuv420p before input I'm getting Option pixel_format not found. Using after -i as output param doesn't change a thing.

This is the full ffprobe info about mp4 I'm dealing with

{
    "streams": [
        {
            "index": 0,
            "codec_name": "h264",
            "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
            "profile": "High",
            "codec_type": "video",
            "codec_tag_string": "avc1",
            "codec_tag": "0x31637661",
            "width": 1280,
            "height": 720,
            "coded_width": 1280,
            "coded_height": 720,
            "closed_captions": 0,
            "film_grain": 0,
            "has_b_frames": 2,
            "sample_aspect_ratio": "1:1",
            "display_aspect_ratio": "16:9",
            "pix_fmt": "yuv420p",
            "level": 31,
            "chroma_location": "left",
            "field_order": "progressive",
            "refs": 1,
            "is_avc": "true",
            "nal_length_size": "4",
            "id": "0x1",
            "r_frame_rate": "24000/1001",
            "avg_frame_rate": "24000/1001",
            "time_base": "1/24000",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 4393389,
            "duration": "183.057875",
            "bit_rate": "3001682",
            "bits_per_raw_sample": "8",
            "nb_frames": "4389",
            "extradata_size": 45,
            "disposition": {
                "default": 1,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0,
                "timed_thumbnails": 0,
                "captions": 0,
                "descriptions": 0,
                "metadata": 0,
                "dependent": 0,
                "still_image": 0
            },
            "tags": {
                "language": "und",
                "handler_name": "VideoHandler",
                "vendor_id": "[0][0][0][0]"
            }
        },
        {
            "index": 1,
            "codec_name": "aac",
            "codec_long_name": "AAC (Advanced Audio Coding)",
            "profile": "LC",
            "codec_type": "audio",
            "codec_tag_string": "mp4a",
            "codec_tag": "0x6134706d",
            "sample_fmt": "fltp",
            "sample_rate": "48000",
            "channels": 2,
            "channel_layout": "stereo",
            "bits_per_sample": 0,
            "id": "0x2",
            "r_frame_rate": "0/0",
            "avg_frame_rate": "0/0",
            "time_base": "1/48000",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 8790000,
            "duration": "183.125000",
            "bit_rate": "128606",
            "nb_frames": "8585",
            "extradata_size": 5,
            "disposition": {
                "default": 1,
                "dub": 0,
                "original": 0,
                "comment": 0,
                "lyrics": 0,
                "karaoke": 0,
                "forced": 0,
                "hearing_impaired": 0,
                "visual_impaired": 0,
                "clean_effects": 0,
                "attached_pic": 0,
                "timed_thumbnails": 0,
                "captions": 0,
                "descriptions": 0,
                "metadata": 0,
                "dependent": 0,
                "still_image": 0
            },
            "tags": {
                "language": "eng",
                "handler_name": "Stereo",
                "vendor_id": "[0][0][0][0]"
            }
        }
    ],
    "format": {
        "filename": "sample_1280x720_surfing_with_audio.mp4",
        "nb_streams": 2,
        "nb_programs": 0,
        "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
        "format_long_name": "QuickTime / MOV",
        "start_time": "0.000000",
        "duration": "183.147000",
        "size": "71753110",
        "bit_rate": "3134230",
        "probe_score": 100,
        "tags": {
            "major_brand": "isom",
            "minor_version": "512",
            "compatible_brands": "isomiso2avc1mp41",
            "encoder": "Lavf58.45.100"
        }
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source