view third_party/ffmpeg/ffmpeg_hls_test.c @ 264:04fee26ecce0

add authenticated JRPG conversation platform Add reusable auth/session storage, owned conversation recovery, guest quotas, admin workflows, URL-routed conversation UI, mobile frame support, and parallel browser acceptance. Co-authored-by: Copilot <[email protected]>
author MrJuneJune <me@mrjunejune.com>
date Fri, 07 Aug 2026 07:34:12 -0700
parents 543df0fe7168
children
line wrap: on
line source

#include "third_party/ffmpeg/ffmpeg_cli.h"

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

static char *read_file(const char *path)
{
  FILE *file = fopen(path, "rb");
  if (!file)
    return NULL;
  fseek(file, 0, SEEK_END);
  long length = ftell(file);
  fseek(file, 0, SEEK_SET);
  char *content = malloc((size_t)length + 1);
  fread(content, 1, (size_t)length, file);
  content[length] = '\0';
  fclose(file);
  return content;
}

int main(int argc, char **argv)
{
  assert(argc == 2);
  char temporary[] = "/tmp/ffmpeg-hls-test-XXXXXX";
  assert(mkdtemp(temporary));

  Fmp4HlsOpts options = ffmpeg_fmp4_hls_opts_default();
  options.max_width = 480;
  options.max_height = 360;
  options.video_bitrate = 350;
  options.codec = FFMPEG_HLS_VP9_OPUS;
  FfmpegResult result = ffmpeg_video_to_fmp4_hls(
      argv[1],
      temporary,
      "test",
      &options);
  if (result != FFMPEG_OK)
  {
    fprintf(stderr, "%s\n", ffmpeg_last_error());
    return 1;
  }

  char playlist_path[512];
  snprintf(playlist_path, sizeof(playlist_path), "%s/test-stream.m3u8", temporary);
  char *playlist = read_file(playlist_path);
  assert(playlist);
  assert(strstr(playlist, "#EXT-X-MAP:URI=\"test-init.mp4\""));
  assert(strstr(playlist, "test-segment000.m4s"));
  assert(strstr(playlist, "#EXT-X-ENDLIST"));
  free(playlist);

  options.codec = FFMPEG_HLS_H264_AAC;
  options.use_mpeg_ts = true;
  result = ffmpeg_video_to_fmp4_hls(
      argv[1],
      temporary,
      "test-ts",
      &options);
  if (result != FFMPEG_OK)
  {
    fprintf(stderr, "%s\n", ffmpeg_last_error());
    return 1;
  }
  snprintf(
      playlist_path,
      sizeof(playlist_path),
      "%s/test-ts-stream.m3u8",
      temporary);
  playlist = read_file(playlist_path);
  assert(playlist);
  assert(!strstr(playlist, "#EXT-X-MAP"));
  assert(strstr(playlist, "test-ts-segment000.ts"));
  assert(strstr(playlist, "#EXT-X-ENDLIST"));
  free(playlist);

  char cleanup[640];
  snprintf(cleanup, sizeof(cleanup), "rm -rf '%s'", temporary);
  return system(cleanup) == 0 ? 0 : 1;
}